写出来了,不过对线程的使用,理解得还不是很透!
import java.math.*;
import java.awt.*;
public class Zfx extends java.applet.Applet implements Runnable
{
public int i=100,j=100,m=200,n=200;
private Thread runner=null;
public void init()
{
}
public void paint(Graphics g)
{
g.setColor(new Color((int)(255*Math.random()),(int)(255*Math.random()),(int)(255*Math.random())));
/*绘制得正方形是随机颜色*/
g.drawRect(i++,j++,m,n);
/*嵌套绘制*/
g.fillRect(i++,j++,m,n);
m=m-4;n=n-4;
if(m==0||n==0)
{
m=200;
n=200;
i=100;
j=100;
}
}
public void run()
{
while(runner!=null)
{
repaint();
try
{
Thread.sleep(200);
}
catch(InterruptedException e)
{
}
}
}
public boolean handleEvent(Event evt)
{
if(evt.id==Event.WINDOW_DESTROY)
System.exit(0);
return super.handleEvent(evt);
}
public void start()
{
if(runner==null)
{
runner=new Thread(this);
runner.start();
}
}
public void update(Graphics g)
{
paint(g);
}
}