//左手画圆,右手花方的例子!
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Examplelf extends Applet implements Runnable
{
Thread left,right;
Graphics mypen;
int x,y;
public void init ()
{
left=new Thread (this);
right=new Thread (this);
x=10;y=10;
mypen=getGraphics ();
}
public void start ()
{
left.start ();
right.start ();
}
public void run ()
{
while (true)
{
if(Thread.currentThread ()==left)
{
x=x+1;
if (x>20) x=10;
mypen.setColor (Color.blue);
mypen.clearRect (10,10,300,40);
mypen.drawRect (10+x,10,40,40);
try{
left.sleep (60);
}
catch (InterruptedException e) {}
}
else if (Thread.currentThread ()==right)
{
y=y+1;
if (y>240) y=10;
mypen.setColor (Color.red);
mypen.clearRect (10,90,300,40);
mypen.drawOval (10+y,90,40,40);
try{
right.sleep (60);
}
catch (InterruptedException e) {}
}
}
}
}