Java Swing AWT Question:
Download Job Interview Questions and Answers PDF
Write a program to paint the off-screen buffer in swings?
Answer:
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"));
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"));
Download Swing AWT Interview Questions And Answers
PDF
Previous Question | Next Question |
What are the steps required in creating an empty table drop? | How to Parse HTML used Swing? |