将 Java 应用程序变成 Windows 屏幕保护程序

发布于 2024-08-18 23:33:49 字数 98 浏览 4 评论 0原文

我编写了一个程序,通过深度优先搜索来解决迷宫问题。我想知道如何将这个Java程序变成屏幕保护程序应用程序?有没有办法让 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

水染的天色ゝ 2024-08-25 23:33:49

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

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

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

最后,您需要使用 Launch4j 并为其指定 .scr 扩展名。

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.

鼻尖触碰 2024-08-25 23:33:49

我从未使用过这个,但它可能是一个开始的地方。 屏幕保护程序 API


屏幕保护程序 SDK 的链接目前似乎已损坏,因此我链接到索引页:

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.

谁许谁一生繁华 2024-08-25 23:33:49

Windows 屏幕保护程序只是接受某些命令行参数的 exe 文件,详细信息请参见此处

如果你可以将你的java应用程序编译成exe(我不再使用java了,所以我不确定存在什么工具),然后将其重命名为.scr,就可以了。
或者,只需制作一个 .bat 文件,例如:

@echo off
java myProg.class %1

.. 并将其重命名为 .scr

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.

澉约 2024-08-25 23:33:49

我会研究 SaverBeans API,用于在 Java 中创建屏幕保护程序。

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

独﹏钓一江月 2024-08-25 23:33:49

使用 JScreenSaver 库。JScreenSaver 是用Java语言为Windows制作屏幕保护程序的中间件

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

与之呼应 2024-08-25 23:33:49

这种方法的替代方案之一是新的 JavaFX。您可以像在 Swing 中一样创建精美的屏幕保护程序。最重要的是,您可以使用 NetBeans 轻松获得 *.exe 文件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文