您的位置:首页 > 其它

这个怎么运行不出来结果?

2009-06-10 00:41 253 查看
//左手画圆,右手画方!

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) {}

}

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐