java台球游戏04

126 阅读1分钟

/**

  • 测试物体沿着椭圆飞行
  • 最后,实现一个小的台球游戏。
  • @author dell

*/

public class GameFrame04 extends Frame{
	Image img=GameUtil.getImage("images/sun.jpg");
	public void launchFrame(){
		setSize(500,500);
		setLocation(100,100);
		setVisible(true);
		new PaintThread().start();
		addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e){
				System.exit(0);
			}
		});
	}
	private double x=100,y=100;
	private double degree=3.14/3;
	public void paint(Graphics g){
		g.drawImage(img,(int)x,(int)y,null);
		x=100+100*Math.cos(degree);
		y=200+50*Math.sin(degree);
		degree +=0.1;
	}
	
	class PaintThread extends Thread{
		public void run(){
			while(true){
				repaint();
			try{
				Thread.sleep(40);
			}catch(InterruptedException e){
				e.printStackTrace();
			}
			}
		}
	}
	public static void main(String[] args){
		GameFrame04 gf=new GameFrame04();
		gf.launchFrame();
	}
	

}

深圳程序员交流群550846167