📄 donghuaoval.java
字号:
import java.awt.*;
import java.applet.*;
public class donghuaoval extends Applet implements Runnable{
Color nowcolor=Color.black;
public Thread runner;
public int xpos,tag=0;
public Image offscreenImg;
public Graphics offscreenG;
public void init(){
setBackground(Color.white);
setForeground(Color.white);
xpos=50;
offscreenImg=createImage(600,600);
offscreenG=offscreenImg.getGraphics();
}
public void start() {
if (runner == null); {
runner = new Thread(this);
runner.start();
}
}
public void stop() {
if (runner != null) {
runner = null;
}
}
public void run() {
int speed=200;
while(Thread.currentThread()==runner)
{
if(tag==0)
xpos=xpos+10;
else
xpos=xpos-10;
if(xpos==200)
tag=1;
if(xpos==20)
tag=0;
repaint();//no.1 statement
try { Thread.sleep(speed); }
catch (InterruptedException e) { }
}
}
public void paint(Graphics g){
offscreenG.setColor(Color.white);
offscreenG.clearRect(xpos-20,xpos-20,250,250);
int red,green,blue;
red=(int)Math.floor(Math.random()*256);
green=(int)Math.floor(Math.random()*256);
blue=(int)Math.floor(Math.random()*256);
offscreenG.setColor(new Color(red,green,blue));
offscreenG.fillOval(xpos,xpos,xpos,xpos);
g.drawImage(offscreenImg,0,0,this);
}
public void update(Graphics g){
paint(g);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -