JFrame class is a predefined class present in javax.swing package. setLayout method is a predefined method present in JFrame class used to set the layout the frame. BufferedImage class is a predefined class present in java.awt.image package. getGraphics method is a predefined method present in BufferedImage class. Return type of this method is Graphics class object. Syntax-public Graphics getGraphics ().
setColor is a predefined abstract method of Graphics class present in java.awt package used to set the color of Graphics context. Syntax-public abstract void setColor (Color c) drawOval method is a predefined method of Graphics class present in java.awt package used to draw the oval. Syntax-public abstract void drawOval (int, int, int, int) JLabel class is a predefined class present in javax.swing package. add method is a predefined method present in JFrame class. Here it is used to add the label in the frame. setTitle method is a predefined method present in JFrame class used to set the title of the frame.
Syntax-public void setTitle (String s) setSize method is a predefined method present in JFrame class used to set the size of the frame. syntax- public void setSize (int x, int y).
Here is the Java Example forBufferedImage
import java.awt.*;
import javax.swing.*;
import java.awt.image.BufferedImage;
class BufferedImageExample
{
public static void main(String[] args)
{
JFrame panel = new JFrame();
panel.setLayout(new FlowLayout() );
BufferedImage image=new BufferedImage(400,400, BufferedImage.TYPE_INT_ARGB);
Graphics G=image.getGraphics();
G.setColor(Color.blue);
G.drawOval(140, 25, 120, 50);
G.dispose();
JLabel lblOval = new JLabel(new ImageIcon(image));
panel.add(lblOval);
panel.setTitle("Graphics");
panel.setSize(200,150);
panel.setVisible(true);
}
}