tankclient.java

来自「J2SE坦克大战源码 分为24个版本」· Java 代码 · 共 67 行

JAVA
67
字号
//0.3

import java.awt.*;
import java.awt.event.*;


public class TankClient extends Frame{
	
	int x = 50;
	int y = 50;
	
	public void paint(Graphics g){
				
		Color c = g.getColor();
		g.setColor(Color.RED);
		g.fillOval(x, y, 30, 30);
		g.setColor(c);		
		
		y += 1;
		x += 1;
	}
	
	
	public void LauchFrame(){
			
		this.setLocation(400, 300);
		this.setSize(800, 600);	
		this.setTitle("坦克大战");
		this.setResizable(false);
		
		
		this.addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		this.setVisible(true);
		new Thread(new PaintThread()).start();
	}	
	
	public static void main(String[] args) {
	
		TankClient tc = new TankClient();
		tc.LauchFrame();
	
	}
	
	class PaintThread implements Runnable{

		public void run() {
			
			while(true){
				repaint();
				try {
					Thread.sleep(10);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}						
		}
		
		
		
	}
	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?