首先呢, 就算是抄例子,也不能抄错误:)既然线程呢,就一定是实现Runable接口,
而要新建立线程呢,就是new Thread(), 因为Thread类本身就是实现Runable接口的。
Runable()就一个方法run().所以,本程序void run() 就是线程开始运行了。
public class Aninatir extends Applet implements Runnable {

Thread runner;
int x,y;
public void init(){
x=y=0;
} public void start() { 
 //还是运行现成
runner = new Thread(this);
runner.start();
} public void run() {
while (true) {
x += 4;
y += 4;
repaint();
try {
Thread.sleep(250);
} catch (InterruptedException e) {
;
}
}
} public void paint(Graphics g) {
g.fillOval(x, y, 50, 5);
}
}

解决方案 »

  1.   

    thread .sleep()是线程开始运行之后,为了把cpu资源让给其他线程来运行,先让当前线程休眠一段时间,然后再接着运行该线程
      

  2.   

    init()
      |
    start()
      |           |---paint()
    run()---------|---sleep(250)
      |           |---repaint()
    stop()