Write a program to paint the off-screen buffer in swings?

Submitted by: Administrator
To paint the off-screen buffer in swings requires the paint component that is using an image allowing easy to create set of images and its components in different states. This image that is stored, remain useful for automated regression testing that is also known as the golden image approach that is used to compare the images with the current and old images that uses the last stable build of the image. The code that displays it is as follows:

JButton b = new JButton("Image buffer");
button.setSize(100, 50);
// This set the initial size of the image.
BufferedImage image = new BufferedImage(b.getWidth(), b.getHeight(),
BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
button.paint(g);
ImageIO.write(image, "png", new File("image.png"));
Submitted by: Administrator

Read Online Swing AWT Job Interview Questions And Answers