将 Java 应用程序变成 Windows 屏幕保护程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2135982/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Turn Java App into Windows Screensaver
提问by citronas
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?
我写了一个程序,用深度优先搜索解决迷宫问题。我想知道如何将这个 Java 程序变成屏幕保护程序应用程序?当屏幕保护程序通常被激活时,有没有办法让 Windows 7 启动我的应用程序?
采纳答案by Tendayi Mawushe
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.
Windows 屏幕保护程序只是接受某些命令行参数的程序。因此,为了让您的程序可以作为屏幕保护程序运行,您必须对其进行编码以接受这些参数。
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:
接下来,您可能希望屏幕保护程序以全屏模式运行。这在 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);
}
}
Finally you will need to make your Java program into a Windows executable using something like Launch4jand give it .scr
extension.
最后,您需要使用Launch4j 之类的工具将 Java 程序转换为 Windows 可执行文件并为其提供.scr
扩展名。
回答by Blorgbeard is out
Windows screensavers are just exe files that accept certain command-line arguments, detailed here.
Windows 屏幕保护程序只是接受某些命令行参数的 exe 文件,详情见此处。
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:
如果您可以将您的 java 应用程序编译成一个 exe(我不再使用 java,所以我不确定存在哪些工具),然后将其重命名为 .scr,就可以了。或者仅仅制作一个 .bat 文件就足够了:
@echo off
java myProg.class %1
.. And rename it to .scr
.
.. 并将其重命名为.scr
.
回答by Vincent Ramdhanie
I have never used this but it might be the place to start. Screen Saver API.
我从未使用过这个,但它可能是一个开始的地方。屏幕保护程序 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.
屏幕保护程序 SDK 的链接目前似乎已损坏,因此我链接到索引页面:JDIC。当他们修复他们的链接时,我会调整这个。
回答by Mark B
I would look into the SaverBeansAPI for creating screen savers in Java.
我会研究SaverBeansAPI 以在 Java 中创建屏幕保护程序。
回答by JSI
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.
这种方法的替代方法之一是新的 JavaFX。您可以像在 Swing 中一样创建精美的屏幕保护程序。最重要的是,您可以使用 NetBeans 轻松获得 *.exe 文件。
回答by Extreme Coders
Use the JScreenSaverlibrary.JScreenSaver is the middleware to make a screen saver for Windows in Java language
使用JScreenSaver库。JScreenSaver是用 Java 语言为 Windows 制作屏幕保护程序的中间件