将Java App变为Windows屏幕保护程序 [英] Turn Java App into Windows Screensaver

查看:172
本文介绍了将Java App变为Windows屏幕保护程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个用深度优先搜索解决迷宫的程序。我想知道如何将这个Java程序变成Screensaver应用程序?当屏幕保护程序通常被激活时,有没有办法让Windows 7启动我的应用程序?

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?

推荐答案

Windows屏幕保护程序只是程序接受某些命令行参数。因此,为了使您的程序可以作为屏幕保护程序运行,您必须对其进行编码以接受这些参数。

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.

接下来您可能希望屏幕保护程序以全屏运行模式。这在Java中非常简单,如下例所示:

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);
    }
}

最后,您需要将Java程序变为使用 Launch4j 之类的Windows可执行文件,并将其 .scr 扩展。

Finally you will need to make your Java program into a Windows executable using something like Launch4j and give it .scr extension.

这篇关于将Java App变为Windows屏幕保护程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆