This Java tips illustrates a method of capturing a Screen shot. Java provides java.awt.Robot class which provides createScreenCapture method for capturing an area on the sreen. Developer can specify the coordinates of the area to be captured.

   try {

        Robot robot = new Robot();
    
        // Capture a particular area on the screen
        int x = 100;
        int y = 100;
        int width = 200;
        int height = 200;
        Rectangle area = new Rectangle(x, y, width, height);
        BufferedImage bufferedImage = robot.createScreenCapture(area);
    
        // Capture the whole screen
        area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
        bufferedImage = robot.createScreenCapture(area);

    } catch (AWTException e) {
    }

   try {

        Robot robot = new Robot();
    
        // Capture a particular area on the screen
        int x = 100;
        int y = 100;
        int width = 200;
        int height = 200;
        Rectangle area = new Rectangle(x, y, width, height);
        BufferedImage bufferedImage = robot.createScreenCapture(area);
    
        // Capture the whole screen
        area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
        bufferedImage = robot.createScreenCapture(area);

    } catch (AWTException e) {
    }