I am taking screen captures of my screen using the following example:
try {
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(new Rectangle(0, 0, 200, 200));
} catch java.awt.AWTException exc) {
System.out.println("error: main");
}
Now I want to draw the screen shots on a component of a GUI. I don't know which component I should use, but I want to draw the images every frame(~ 20 FPS are desired), that it looks like a movie, a camera that films my desktop. And, I want to draw boxes over certain areas of the drawn area.
How could I do this? Every example I was shown did following:
- An image gets loaded from file system at start up of the program and drawn to a JPanel, therefore one couldn't paint on it that easily I want to do so.
That doesn't work(grey panel):
visualization = new JPanel();
visualization.setLayout(new BorderLayout());
try {
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(new Rectangle(0, 0, 200, 200));
Graphics2D g = image.createGraphics();
visualization.paint(g);
visualization.setVisible(true);
}
catch(java.awt.AWTException exc) {
System.out.println("error: main");
}