say in my program, i have this paint() method. my wish is to create an image of the rectangles that are drawn (with the for loop). I tried the method below and it did give me those rectangles (blue color), but the background is all black. When I run program without creating image, just drawing the rect on a JFrame, the background is white. How can i fix this. ?
public void paint(Graphics g) {     
    super.paint(g);
    BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
    g = Image.getGraphics();  <<<----- is this correct?
    g.setColor(Color.blue);
    for ( ..... ) {
        g.fillRect(X , Y,  width , height);
            ....        
    }
    try {
    ImageIO.write(image, "jpg", new File("CustomImage.jpg"));
    }catch (IOException e) { 
       e.printStackTrace();
    }
}