This might be very helpful for GUI developer in java. At times its hard to figureout the some error happens in the user end. I mean, End user usually just complain that while clicking so and so button or tab or something it failed. In those cases if you have users screen, you can guess something. To do that, you can make the following code as an API and store screen shot in your log location and you can verify them later.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.Rectangle; | |
import java.awt.Robot; | |
import java.awt.Toolkit; | |
import java.awt.image.BufferedImage; | |
import java.io.File; | |
import javax.imageio.ImageIO; | |
/** | |
* | |
* @author Raghunathan K Semburakkiannan | |
* @since 05/14/2010 | |
* | |
*/ | |
public class ScreenShot { | |
public static void main(String[] args) throws Exception { | |
// create a new instance, automation event generator | |
Robot robot = new Robot(); | |
// capture the screen by getting the default screen size | |
BufferedImage screenShot = robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize())); | |
// write the capture image to a file using ImageIO | |
// format can be be JPG, GIF etc. | |
ImageIO.write(screenShot, "JPG", new File("c:\\screen-shot.jpg")); | |
} | |
} |