gpt4 book ai didi

java - 如何将 Java Applet 更改为 Windows 8.1 的屏幕保护程序?

转载 作者:行者123 更新时间:2023-11-30 08:13:05 25 4
gpt4 key购买 nike

我已经尝试为 Windows 8.1 创建自定义屏幕保护程序有一段时间了。然而,通过我的研究,我对这个主题几乎没有什么兴趣,而且我发现的任何信息要么已经过时,要么来自不值得信任的来源。我使用java已经有大约2年了,但我对一般编程还比较陌生,而且我目前正在使用eclipse作为编译器,请帮忙。这是我目前拥有的:

    import java.applet.Applet;
import java.awt.*;
import java.util.*;
import java.io.*;

@SuppressWarnings("serial")
public class CatScreenSaver extends Applet
{
private int runs;
private Scanner c;
private Scanner c2;
private Font myFont;
private Font error;
private int yLoc;
private boolean dir;
private Random randgen;
private Color col;
private int sleep;
private boolean start;
public CatScreenSaver() throws FileNotFoundException
{
runs = 0;
yLoc = 570;
dir = false;
c = new Scanner(new File("cat.txt"));
myFont = new Font("Consolas", 10, 10);
error = new Font("Consolas", 20, 20);
c2 = new Scanner(new File("cat2.txt"));
randgen = new Random();
sleep = 64;
start=true;
}
public void init()
{
col =Color.LIGHT_GRAY;
setSize(4000,650);
setBackground(Color.BLACK);
}
public void paint(Graphics g)
{
g.setFont(error);
g.setColor(Color.red);
g.drawString("We are experiencing technical difficulties, Please wait...", 250, 50);
g.drawString("In the mean time enjoy this dancing cat!", 250, 70);
if(!dir && !start)
{
try {
printCat(g);
} catch (FileNotFoundException | InterruptedException e) {
e.printStackTrace();
}
}
else if(dir && !start)
{
try {
printCat2(g);
} catch (FileNotFoundException | InterruptedException e) {
e.printStackTrace();
}
}
else if(!dir && start)
{
try {
printSCat(g);
} catch (FileNotFoundException | InterruptedException e) {
e.printStackTrace();
}
}
else if(dir && start)
{
try {
printSCat2(g);
} catch (FileNotFoundException | InterruptedException e) {
e.printStackTrace();
}
}
}
public void printSCat(Graphics g) throws FileNotFoundException, InterruptedException
{
g.setColor(col);
g.setFont(myFont);
int lines;
lines = c.nextInt();
for(int i = 0; i < lines; i++)
{
String str = c.nextLine();
g.drawString(str, yLoc, (i*10));
}
runs++;
if(runs == 31)
{
dir = true;
setScan();
}
Thread.sleep(sleep);
repaint();
}
public void printSCat2(Graphics g) throws FileNotFoundException, InterruptedException
{
g.setColor(col);
g.setFont(myFont);
int lines;
lines = c2.nextInt();
for(int i = 0; i < lines; i++)
{
String str = c2.nextLine();
g.drawString(str, yLoc, (i*10));
}
runs--;
if(runs == 0)
{
dir = false;
setScan();
start = false;
}
Thread.sleep(sleep);
repaint();
}
public void printCat(Graphics g) throws FileNotFoundException, InterruptedException
{
g.setColor(col);
g.setFont(myFont);
int lines;
lines = c.nextInt();
for(int i = 0; i < lines; i++)
{
String str = c.nextLine();
g.drawString(str, yLoc, (i*10));
}
yLoc-=20;
runs++;
if(runs == 31)
{
dir = true;
changeColor();
setScan();
}
Thread.sleep(sleep);
repaint();
}
public void printCat2(Graphics g) throws FileNotFoundException, InterruptedException
{
g.setColor(col);
g.setFont(myFont);
int lines;
lines = c2.nextInt();
for(int i = 0; i < lines; i++)
{
String str = c2.nextLine();
g.drawString(str, yLoc, (i*10));
}
runs--;
yLoc+=20;
if(runs==0)
{
dir = false;
changeColor();
setScan();
}
Thread.sleep(sleep);
repaint();
}
public void changeColor()
{
int rand = randgen.nextInt(10)-1;
if(rand==1)
col = Color.DARK_GRAY;
else if(rand==2)
col = Color.green;
else if(rand==3)
col=Color.BLUE;
else if(rand==4)
col = Color.CYAN;
else if(rand==5)
col =Color.MAGENTA;
else if(rand==6)
col =Color.YELLOW;
else if(rand==7)
col =Color.PINK;
else if(rand==8)
col =Color.ORANGE;
else if(rand==9)
col =Color.LIGHT_GRAY;
else
col =Color.WHITE;
}
public void setScan()throws FileNotFoundException
{
c = new Scanner(new File("cat.txt"));
c2 = new Scanner(new File("cat2.txt"));
}
}

该代码还使用 2 个文本文件“打印”到屏幕

最佳答案

要创建独立的 GUI 应用程序,请使用 java swing 或(最新的)JavaFX,然后您将能够创建独立的 java 应用程序,现在您可以在 JVM 内使用 java 命令运行 gui 应用程序。

为了将 Java 程序设置为在 Windows 中作为屏幕保护程序运行 - 您需要打包 Java 程序 (jar),然后创建某种 exe/scr,以便您可以设置窗口以使用屏幕保护程序运行。

快速谷歌搜索发现下面的链接。也许您也可以对 swing 使用相同的过程。

JavaFX Screensaver

Similiar question

关于java - 如何将 Java Applet 更改为 Windows 8.1 的屏幕保护程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30084027/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com