/**
  * java绘图的基本原理:画一个圆
  * @author tfq
  * @date 2011-08-27
  */import javax.swing.*;
 import java.awt.*;public class DrawCicle extends JFrame{
 MyPanel mp=null;
  
  public static void main(String[] args) {
   DrawCicle dc=new DrawCicle();
  }
  
  public DrawCicle(){
   mp =new MyPanel();
   this.add(mp);
   this.setSize(300, 250);
   this.setLocation(600, 300);
   this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
   this.setVisible(true);
  }
 }/**
  * 画图的一个面板并且还要显示
  * @author tfq
  *
  */
 class MyPanel extends JPanel{
  
  /**
   * 覆盖JPanel 的paint()方法
   * Graphics相当于绘图的一支画笔类
   * paint在当前面板初始化时补调用,还有窗口变大变小时会调用,窗口最大化最小化时也会调用
   */
  public void paint(Graphics g){
   //调用父类函数完成初始化
   //这句不能少
   super.paint(g);
   System.out.println("piant()被调用!");
   //先画一个圆
   //g.drawOval(10, 10, 30, 30);
   //画直线
   //g.drawLine(10, 20, 100, 20);
   //画矩形 第一个参表示与当前窗体的左上角x轴距离,第二个参数表示与当前窗体的左上角y轴距离,第三第四表示矩形的宽高
   //g.drawRect(0, 0, 50, 60);
   //填充矩形色
   g.setColor(Color.GREEN);
   g.fillRect(0, 0, 50, 60);
  }
 }