Turn Java App into Windows Screensaver

人盡茶涼 提交于 2019-11-29 21:53:59

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.

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.

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.

I would look into the SaverBeans API for creating screen savers in Java.

Use the JScreenSaver library.JScreenSaver is the middleware to make a screen saver for Windows in Java language

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!