package com.zhushen.Test;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/**
* 游戏窗口类
* @author zhushen
*
*/
public class GameFrame extends Frame {
private static final long serialVersionUID = 1L;
Image img=GameUtil.getImage("images/mylove.png");
/**
* 加载游戏窗口
* @param x
* @param y
* @param width
* @param height
*/
public void launchFrame(int x,int y,int width,int height){
setSize(width,height);
setLocation(x,y);
setVisible(true);
new PaintThread().start();//启动重画线程
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){
System.exit(0);
}
}) ;
}
/**
* 在窗口里面画元素
*/
private double x=100,y=100;
public void paint(Graphics g){
g.drawImage(img, (int)x, (int)y, null);
// x+=3;
y+=10;
}
/**
* 定义一个重画窗口的线程类,内部类
* @author zhushen
*
*/
class PaintThread extends Thread{
public void run(){
while(true){
repaint();
try {
Thread.sleep(40);//1s画1000/40次
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public static void main(String[] args) {
GameFrame gf=new GameFrame();
gf.launchFrame(100,100,500,500);
}
}
79_游戏项目_动画的实现
最新推荐文章于 2018-04-20 10:38:24 发布