by Dinesh Thakur Category: AWT and Applets

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);
        }
}

BufferedImage to Image in Java



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles