我正在尝试编写我的第一个Java小程序,在我开始后不久,我已经遇到了2个问题。
我已经搜索了问题,但找不到任何东西。
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.CropImageFilter;
import java.awt.image.FilteredImageSource;
import javax.swing.ImageIcon;
import javax.swing.JApplet;
public class start extends JApplet implements Runnable{
public boolean pause = false;
public Image bg;
public Image back;
public Image ground;
public Image front;
public void init(){
setSize(800, 450);
bg = getImage(getCodeBase(),"res/bg.PNG");
back = getImage(getCodeBase(),"res/back.PNG");
ground = getImage(getCodeBase(),"res/ground.PNG");
front = getImage(getCodeBase(),"res/front.PNG");
}
public void start(){
Thread game = new Thread();
game.start();
run();
}
public void stop(){
}
public void destroy(){
}
public void run(){
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
// while(!pause){
// repaint();
//
// try{
// Thread.sleep(25);
// }catch(InterruptedException e){
//
// }
// }
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
}
public void paint(Graphics g){
g.drawImage(bg, 10, 10, this);
g.drawImage(back, 10, 10, this);
g.drawImage(ground, 10, 10, this);
g.drawImage(front, 10, 10, this);
}
}
答案 0 :(得分:0)
我认为您正在尝试执行此处的示例:Java: In what order are the methods called in an Applet?如果您注意到,使用的Thread的构造函数引用了this
,顺便说一句,你不要需要自己调用run
,因为这是Thread类的一部分。