I wrote a program that solves mazes with depth-first search. I was wondering how to turn this Java program into a Screensaver application? Is there a way that Windows 7 starts my app when the screensaver would normally be activated?
-
What platform? windows? mac? linux? commodore 64? – Byron Whitlock Jan 25 '10 at 22:02
-
@Byron Whitlock: Oh sorry, forgot to mention: Windows 7. I edited my question. – citronas Jan 25 '10 at 22:06
-
Did you ever make your java app into a screensaver? I'm trying to do the same thing, and would be interested to hear how it went for you. – LarsH Mar 06 '12 at 04:06
-
@LarsH: Unfortunately I haven't gotten to that yet :-( There's always so much to do. – citronas Mar 09 '12 at 13:20
6 Answers
A Windows screen saver is just program that accepts certain command line arguments. So in order to have your program be runnable as a screen saver you must code it to accept those arguments.
Next you will probably want your screen saver to run in full screen mode. This is very simple to do in Java as the example below shows:
public final class ScreenSaver {
public static final void main(final String[] args) throws Exception {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
final JFrame screenSaverFrame = new JFrame();
screenSaverFrame.setDefaultCloseOperation(
WindowConstants.EXIT_ON_CLOSE);
screenSaverFrame.setUndecorated(true);
screenSaverFrame.setResizable(false);
screenSaverFrame.add(new JLabel("This is a Java Screensaver!",
SwingConstants.CENTER), BorderLayout.CENTER);
screenSaverFrame.validate();
GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice()
.setFullScreenWindow(screenSaverFrame);
}
}
Finally you will need to make your Java program into a Windows executable using something like Launch4j and give it .scr
extension.

- 25,562
- 6
- 51
- 57
-
1Seems like beyond just accepting certain command line arguments, it has to be able to show its preview in a parent window, instead of in its own frame, right? How do you do that? without JDIC. Also, when in settings mode, where do you store (persist) the settings? – LarsH Mar 07 '12 at 04:31
I have never used this but it might be the place to start. Screen Saver API.
The link to the screensaver SDK seems to be broken at the moment so I am linking to the index page: JDIC. When they fix their link I'll adjust this.

- 102,349
- 23
- 137
- 192
Windows screensavers are just exe files that accept certain command-line arguments, detailed here.
If you can compile your java app into an exe (I don't use java much any more so I'm not sure what tools exist), then rename it to .scr, that would do it. Or it might be enough just to make a .bat file like:
@echo off
java myProg.class %1
.. And rename it to .scr
.

- 101,031
- 48
- 228
- 272
-
1Renaming .bat to .scr does not work, the file must be exe format (Windows 10). – DuncG Dec 09 '20 at 12:32
I would look into the SaverBeans API for creating screen savers in Java.

- 183,023
- 24
- 297
- 295
-
Full source code is hard to find, but it looks like has been copied here: https://github.com/youngnh/saverbeans – user2957009 Dec 28 '19 at 21:18
Use the JScreenSaver library.JScreenSaver is the middleware to make a screen saver for Windows in Java language

- 3,441
- 2
- 39
- 55
One of the alternative to this approach is the new JavaFX. You can create fancy screen saver in the same way you do it in Swing. On top of that you get *.exe file quite easily using NetBeans.

- 1