int width = 1024;
int height = 768;
// we're going to use RBG coloring. There are a bunch of different types, though
BufferedImage image= new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
// now drawing is just like painting a component
g.setColor(new Color(0.2f, 0.4f, 0.2f));
// make the background a slight shade of green
g.fillRect(0, 0, width, height);
g.setColor(new Color(1.0f, 0.0f, 0.0f));
// draw a red circle
g.drawCircle(0, 0, width, height);
// now to save the image
try
{
ImageIO.write(image, "png", new File("test.png"));
}
catch (IOException exception)
{
exception.printStackTrace();
}