Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn Java App into Windows Screensaver

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?

like image 610
citronas Avatar asked Jan 25 '10 22:01

citronas


5 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.

like image 97
Tendayi Mawushe Avatar answered Oct 29 '22 04:10

Tendayi Mawushe


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.

like image 45
Vincent Ramdhanie Avatar answered Oct 29 '22 05:10

Vincent Ramdhanie


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.

like image 23
Blorgbeard Avatar answered Oct 29 '22 05:10

Blorgbeard


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

like image 25
Mark B Avatar answered Oct 29 '22 06:10

Mark B


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

like image 38
Extreme Coders Avatar answered Oct 29 '22 06:10

Extreme Coders