首页 新闻 搜索 专区 学院

java初学者求解,为什么只有窗体没有图片

0
[待解决问题]

package Tank;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;

public class GameWindow extends Frame {

Enemy_Tank enemyTank1 = new Enemy_Tank ();
Enemy_Tank enemyTank2 = new Enemy_Tank ();
My_Tank myTank = new My_Tank ( ); 						//构造坦克对象

Tank [] tanks = new Tank [] {enemyTank1, enemyTank2, myTank };

public void startFrame(){ 	  										
	this.addWindowListener(new WindowAdapter()                     //关闭按钮
    {
           public void windowClosing(WindowEvent e)
           {
               System.exit(0);
             }
    });

	setTitle("tank_Game");
    setSize (800,600); 			//设置游戏窗体的宽高
    setBackground(new Color(111 , 111 , 111));
    setVisible(true); 				//窗体可见
    new PaintThread ().run(); 	//启动动画线程
    this.addKeyListener ( new keyboardListener() );  	//监听键盘事件
}

public void paint (Graphics g) {
	for (int i = 0 ; i < tanks.length ; i++ ) {
		tanks [i] . paint (g); 		//多态的体现
	}
}

class keyboardListener extends KeyAdapter {
    public void keyPressed (KeyEvent e ) {
        myTank.move (e);
    }
}
class PaintThread extends Thread {
    public void run () {
        while (true) {
            repaint(); 	//重绘画面
            try {
                Thread.sleep(40); 		//每隔40ms重绘一次
            }
            catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

}

2241085635的主页 2241085635 | 菜鸟二级 | 园豆:202
提问于:2021-02-27 15:21
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册