import java.awt.AWTException;
import java.awt.Color;
import java.awt.Frame;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author andrei-eremeev
*/
public class TwoScreenCaptureTest {
public static void main(String[] args) throws InterruptedException, AWTException, IOException {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gds = ge.getScreenDevices();
List frames = new ArrayList();
Robot robot = new Robot();
for (int i = 0; i < gds.length; ++i) {
GraphicsDevice gd = gds[i];
Frame frame = new Frame("Frame", gd.getDefaultConfiguration());
frames.add(frame);
frame.setSize(200, 200);
Rectangle bounds = gd.getDefaultConfiguration().getBounds();
frame.setLocation(100 + bounds.x, 100 + bounds.y);
frame.setBackground(Color.BLUE);
frame.setVisible(true);
Thread.sleep(2500);
BufferedImage image = robot.createScreenCapture(frame.getBounds());
ImageIO.write(image, "png", new File("Frame" + i));
}
for (Frame frame : frames) {
System.out.println(frame.getBounds());
frame.dispose();
}
}
}