马士兵坦克大战

创建窗口并关闭窗口,并改变窗口背景颜色和在窗口中画出实心圆

import java.awt.*;
import java.awt.event.*;
/**
 * 产生一个窗口
 * @author Administrator
 *
 */
public class TankClinent extends Frame{
    @Override//重写print方法,画图
    public void paint(Graphics g) {
        Color c=g.getColor();//创建一个颜色对象
        g.setColor(Color.RED);//该颜色为红色
        g.fillOval(50, 50, 30, 30);//以距离窗口左上角(50,50),长宽都为30正方形为做内切实心圆
        g.setColor(c);
    }
    public void LaunchFrame(){
        this.setLocation(400,300);//设定窗口位置
        this.setSize(800, 600);//设定窗口规格(长和宽)
        this.setTitle("TankWar");//标题栏的文字
        //关闭窗口
        this.addWindowListener(new WindowAdapter(){//用匿名类来写窗口关闭,类短小,不涉及将来的扩展,不涉及重要业务逻辑

            public void windowClosing(WindowEvent e) {

                System.exit(0);
            }   
        });
        this.setResizable(false);//窗口大小不可调节
        this.setBackground(Color.GREEN);//设置背景颜色为绿色
        setVisible(true);//显现窗口
    }
    public static void main(String[]args){
        TankClinent tc=new TankClinent();
        tc.LaunchFrame();
    }
}

猜你喜欢

转载自blog.csdn.net/lpq1201/article/details/78019949