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

public class PaintApp extends Frame 
		implements ActionListener{

	int edge=400; //方形图的边长
	Button btn=null;

	public PaintApp(){
		setLayout(null);//不再使用布局管理器
		setBounds(0,0,edge,edge);//设置窗口大小

		//构造按钮
		btn=new Button("Click Me");		
		btn.setBounds(new Rectangle(edge/3*2,edge/3*2,60,40));		
		add(btn,null);
		btn.addActionListener(this);

		//设置退出按钮
		Button quit=new Button("退出");
		quit.setBounds(new Rectangle(30,30,30,20));
		add(quit,null);
		quit.addActionListener(//使用了匿名内部类
				new ActionListener(){
					public void actionPerformed(ActionEvent e){
						System.exit(0);
					}
				}
			);

		setVisible(true);
	}

	public void actionPerformed(ActionEvent e){
		edge=(edge>400)? 400:700;
		repaint();//注释掉该行后再运行程序看看有何不同
	}
	public void paint(Graphics g){
		//设置窗口大小
		setBounds(0,0,edge,edge);

		//设置黑色背景及其大小
		g.setColor(Color.BLACK);
		g.fillRect(20,20,edge,edge);

		//画月亮
		g.setColor(Color.YELLOW);
		g.fillOval(edge/4*3,edge/4,edge/5,edge/5);

		//设置字体及前景颜色
		g.setColor(Color.WHITE);
		g.setFont(new Font("隶书",Font.ITALIC,30));
		//画诗句
		g.drawString("明月几时有",edge/5,edge/2+50);
		g.drawString("把酒问晴天",edge/5,edge/2+100);
		//设置按钮显示的位置
		btn.setBounds(new Rectangle(edge/3*2,edge/3*2,60,40));	

	}//end paint

	public static void main(String[] args){
		PaintApp p=new PaintApp();
	}

}
