Java Graphics_2

package com.han;

import java.awt.Container;
import java.awt.Graphics;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Graphics_2 extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2196445899859855213L;
	
	private static final int OVAL_WIDTH = 80;
	private static final int OVAL_HEIGHT = 80;
	
	@SuppressWarnings("serial")
	public Graphics_2() {
		// TODO Auto-generated constructor stub
		Container container = getContentPane();
		JPanel panel = new JPanel() {
			@Override
			public void paint(Graphics g) {
				super.paint(g); // for the one containing children components, this is necessary.
				g.drawOval(10, 10, OVAL_WIDTH, OVAL_HEIGHT);
				g.drawOval(80, 10, OVAL_WIDTH, OVAL_HEIGHT);
				g.drawOval(150, 10, OVAL_WIDTH, OVAL_HEIGHT);
				g.drawOval(50, 70, OVAL_WIDTH, OVAL_HEIGHT);
				g.drawOval(120, 70, OVAL_WIDTH, OVAL_HEIGHT);
			}
		};
		container.add(panel);
		JLabel label = new JLabel("Five circles");
		panel.add(label);
		JButton button = new JButton("HAN Gaowen");
		panel.add(button);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Graphics_2 frame = new Graphics_2();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setTitle("Draw circles");
		frame.setSize(300, 200);
		frame.setVisible(true);
	}

}


你可能感兴趣的:(Java Graphics_2)