各位为什么启动线程会出错?
public class WbicCaod extends JFrame{Image nusm=GameUtil.getImage("images/nusm.png");
Image jtpw=GameUtil.getImage("images/jtpw.png");
//绘制图形
int nusmX=250,nusmY=250;
public void paint(Graphics g) {
g.drawImage(jtpw, 0, 0, null);
g.drawImage(nusm, nusmX,nusmY, null);
nusmY++;
}
//重画窗口
class MwukXgrk extends Thread{
@Override
public void run() {
while (true) {
System.out.println("画一次");
repaint();//重画窗口
try {
Thread.sleep(40);//1s=1000ms
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
//创建主窗口
public void launchFrame() {
this.setTitle("标题");
this.setVisible(true);//显示窗口
this.setSize(500,500);//窗口大小
this.setLocation(300,300);//窗口位置
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
new PaintThread().start();
}
public static void main(String[] args) {
WbicCaod a =new WbicCaod();
a.launchFrame();
}