[英]Java applet wont show image
I was trying to program my first Java applet and shortly after I started, I already have 2 problems. 我试图对我的第一个Java applet进行编程,而在开始后不久,我已经遇到了2个问题。
I already searched for the problem, but I can't find anything. 我已经搜索了问题,但是什么也找不到。
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);
}
}
I think that you're trying to do what the example in here: Java: In what order are the methods called in an Applet? 我认为您正在尝试执行以下示例: Java:Applet中的方法以什么顺序调用? does, if you note, the constructor of Thread used have reference to
this
and by the way, you don't need to call run
yourself as this is part of the Thread class. 如果您注意到的话,使用的Thread的构造函数确实
this
进行了引用,而且,您不必自己run
因为这是Thread类的一部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.