我写了一个用线程写了一个小程序,但启动时老说未初始化小程序,不知是何因,?
import java.awt.*;
import java.net.*;
import javax.swing.*;
public class appt extends JApplet implements Runnable {
Thread t=null;
int y=300;
ImageIcon ima[]=new ImageIcon[3];
URL u=null;
int i=0;
public appt(){
super();
for(i=0;i<3;i++){
u=this.getClass().getResource("香/"+i+".jpg");
ima[i]=new ImageIcon(u);
}
}
public void init(){
t = new Thread(this);
t.start();
}
public void start(){
}
public void paint(Graphics g){
g.setColor(Color.BLACK);
g.fillRect(0, 0, this.getWidth(),this.getHeight());
g.setColor(Color.red);
g.fillOval(50,y,100,100);
y=(y>0?y-15:300);
g.drawImage(ima[i].getImage(),0,0,this);
i=(i<2?i+1:0);
}
public void stop(){
}
public void run() {
while(true){
try {
Thread.sleep(400);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}repaint();
}
}
}