package 日食;
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class Moon1 extends Applet implements Runnable{
private int x1=10;//位置坐标
private int y1=15;
private int x2=60;
private int y2=65;
private Thread thread;
public void paint(Graphics g){
x1 = x1+1;
//位置水平坐标每次递增
y1=y1+1;
g.setColor(Color.blue); //设置图形颜色
g.fillOval(x1, y1, 50, 50); //画图(有填充)
x2 = x2+2;
//y2=y2-5;
g.setColor(getBackground());
g.fillOval(x1,y2,40,40);
}
public void start(){
if(thread == null){
thread = new Thread(this); //新建线程
thread.start(); //启动线程
}
}
public void stop(){
if(thread != null){
thread.interrupt(); //中断线程
thread = null;
}
}
public void run() {
while(thread != null){
repaint(); //重绘屏幕
try {
thread.sleep(20); //线程睡眠
} catch (InterruptedException e) {
break;
}
}
}
}