package test;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import test.GameFrame03.PaintThread;
/**
* 加载窗口
* @author Administrator
*
*/
public class MyFrame extends Frame {
public void launchFrame(){
setSize(Constant.GAME_HEIGHT,Constant.GAME_WIDTH); //窗口的大小设置
setLocation(100,100); //点的坐标
setVisible(true); //可视
new PaintThread().start();//启动重画线程
addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
/**
* 定义一个重画窗口的线程类,是一个内部类
* @author Administrator
*
*/
class PaintThread extends Thread{
public void run(){
while(true){ //死循环
repaint();
try {
Thread.sleep(40);
} catch (InterruptedException e) {
e.printStackTrace();
} //1s = 1000ms
}
}
}
}