run()新手的事情,但无法找到答案。 (小程序)

时间:2012-03-12 02:17:28

标签: java applet

好的,所以我有一个简单的Mario applet,什么都不做。我没有做错什么(说不存在错误报告),但它仍然无法正常工作。我的意思是

中没有任何内容
  public void run() {
etc
    }

发生。即便在(真实)。

下面是一个不起作用的样本(取出了刚刚添加的更大的部分。)

public class Main extends Applet implements Runnable {

 //BLAHBLAHBLAH STUFF THAT HAS NOTHING TO DO WITH THE PROBLEM

public void run (){
    Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
    while(true){
        xPos += xSpeed;
        yPos ++;

        try{
            Thread.sleep (20);
        } catch (InterruptedException ex) {

        } 

    Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
    } 

}

    //MORE UNIMPORTANT STUFF

    }

start()方法

public void start() {

    Thread th = new Thread();
    th.start();

    Mario.xSpeed = 1;
    Mario.ySpeed = 1;
    Mario.radius = 25;
    Mario.xPos = 0;
    Mario.yPos = 125;

}

1 个答案:

答案 0 :(得分:2)

Thread th = new Thread();

问题出在这条线上。您需要将类(即this)作为参数传递给构造函数。