注册 登录
编程论坛 JAVA论坛

各位为什么启动线程会出错?

JHxc 发布于 2019-08-03 14:07, 2121 次点击
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();
    }
只有本站会员才能查看附件,请 登录
2 回复
#2
林月儿2019-08-04 04:19
报错信息找不到对应行,猜不出来
#3
GrayJerry2019-09-26 11:22
代码中,没有PaintThread这个类
1