Using my previous posts on how to take a screenshot and how to save an image to disk, I’ve created a Screen Capture Utility extending these basic ideas to create a program that would automate the process of taking multiple screenshots over a period of time. Full source code is available for download here.
Features
- Uses Swing GUI
- Allows you to set the path to save the screenshots to.
- Allows you to set the “capture rate” (how often to take a screenshot) in seconds, minutes, or hours using a timer.
- Allows you to set the timeout period (when it should stop taking screenshots) in seconds, minutes, or hours using a timer.
- Option for saving the screenshots as GIF, JPG, or PNG.
- “Stealth” mode for taking screenshots discretely, including password protection for disabling stealth mode.
- System Tray functionality (minimization, tooltips, and pop-up menu).
The Code
Since the code is too long to post (over 1,000 lines), you may download the entire source by clicking here. I will briefly go over the classes in the project below:
Packages and Files
- (default package)
- ScreenCapture.java – Contains the main method for this project. Use this to start up the application.
- SimpleScreenCapture.java – Previous, simpler application for just taking screenshots and displaying them in a JFrame. Unused for this project, but left for reference.
- gui
- ScreenCaptureGUI.java – This is the meat of the project. It contains all of the GUI and action methods.
- handlers
- GUIHandler.java – The action listener for the GUI.
- img – Contains all of the images used for the project (buttons, JFrame icons, system tray icons, etc.).
- menus
- TrayMenu.java – The GUI for the system tray menu, and also contains a TrayMenuHandler class to handle the menu events.
- util
- Constants.java – Contains constants used for the project. Most of the string literals were exported to this class file to make for easier updates.
- Timestamp.java – Simple timestamp utility class used for appending the time to the screenshot file names.
Screenshots
Main Window
The following screenshot shows the application when it is first started up.
Running (Capturing)
The following screenshot shows the application while it is running (capturing screenshots). Not much going on here — just different buttons enabled / disabled.
Output
The following screenshot shows the output from the above selection.
Conclusion
If you browse through the code, you can see that it really wasn’t too difficult to expand on the previous two basic ideas of screen capturing and saving the images to disk to produce this somewhat handy utility. The main component that made this process “automated” is the use of the java.util.Timer class — one timer to capture the screenshot every t1 period of time, and one timer to stop the process after a t2 period of time.
Questions, comments, bugs?
If you have any questions or comments, or if you notice any bugs in this application, please let me know. If you’ve made any enhancements to the code, please feel free to share it!
