Hello,
My program needs to capture the screen every 1 second until stopped by pressing the GUI button.
In the GUI class I used a for loop to go infinite, but that probably does not work because it takes time to capture, & save screenshot, but the for loop fires before that, thus giving errors, and IO exceptions.
I am now trying to sleep/wait the program somehow for 1-2 seconds between each shot taken.
Unfortunately, I am unable to get the "thread" code going write. May be too confused.
Can someone please modify the below to use "threads", which waits 2 seconds between each shot taken?
public class ScreenShotRobot {
boolean captureScreenShot(String uploadPath, String mode, String filename){
boolean isSuccesful = false;
Rectangle screenRect = new Rectangle( Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage capture;
try {
capture = new Robot().createScreenCapture(screenRect);
ImageIO.write(capture, mode, new File( uploadPath, filename));
//should wait here for 2 seconds, then loop back
isSuccesful = true;
}catch( Exception e ){ isSuccesful = false; }
return isSuccesful;
}
}