请高手解决问题,为啥运行时有问题。
import java.applet.*;import java.awt.*;import java.awt.event.*;
public class fyThread 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> 240) x=10;
mypen.setColor(Color.blue);
mypen.clearRect(10,10,300,100);
mypen.drawRect(10+x,10,50,50);
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,110,300,100);
mypen.drawOval(10+y,110,50,50);
try{right.sleep(60); }
catch(InterruptedException e){}
}
}
public void stop()
{left=null;right=null;
}
}
------解决方案--------------------我靠,这样的代码风格太酷了,看了就想吐!
拜托先格式化一下撒!
------解决方案--------------------ctrl+shift+f一下哦
------解决方案--------------------有什么问题?