⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 screensaver.java

📁 针对越来越多的用户喜欢JAVA
💻 JAVA
字号:
import java.awt.*;
import java.applet.*;

public class ScreenSaver extends Applet implements Runnable
{
int currentX=5,currentY=5,x=0,y=0,k=1;
Thread m_Draw = null;
int newColor;
public void init()
{
m_Draw = new Thread(this);
}
public void paint(Graphics g)
{
g.setColor(new Color(newColor));
g.fillOval(x,y,currentX,currentY);
}
public void start()
{
m_Draw.start();
try{
Thread.sleep(50);
}catch(InterruptedException e) { }
}
public void stop()
{
if(m_Draw.isAlive())
m_Draw.stop();
}
public void run()
{
try
{
while(true)
{
currentX++;
currentY++;
if((currentX-x)>150 || (currentY-y)>100)
{
x = (int)(Math.random()*300);
y = (int)(Math.random()*200);
newColor = (int)(Math.random()*Integer.MAX_VALUE);
currentX = 0;
currentY = 0;
}
showStatus(x+","+y+":"+newColor+"子线程在活动! ");
repaint();
Thread.sleep(100);
}
}
catch(InterruptedException e)
{}
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -