老师,这个程序飞机不移动,为什么啊
package cn.sxt.game;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.Frame;
/*
* 飞机小游戏
*/
public class MyGameFrame extends Frame {
Image plane=GameUtil.getImage( "images/plane.png");
Image bg=GameUtil.getImage("images/bg.jpg");
static int count=0;
int planeX=100,planeY=100;
public void paint(Graphics g) { //自动被调用,g相当于一支画笔
System.out.println("绘制窗口次数:"+count);
count++;
g.drawImage(bg, 0, 0,null);
g.drawImage(plane, 100, 100,null);
planeX+=10;
}
public void launchFrame() {
this.setTitle("小飞机大战");
this.setSize(500,500);
this.setLocation(300,200);
this.setVisible(true);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
new PaintThread().start();//启动重画窗口的线程
}
/*
* 定义了一个重画窗口的线程类
* 定义成内部类是为了方便直接使用窗口类的相关方法
*/
class PaintThread extends Thread{
public void run() {
while(true) {
repaint();//内部类可以直接使用外部类的成员
try {
Thread.sleep(50); //1s=1000ms,1s画20次(20*50=1000)
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public static void main(String[] args) {
MyGameFrame f=new MyGameFrame();
f.launchFrame();
}
}