package java2D;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.SystemColor;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import java.awt.geom.Line2D.Float;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;

import javax.swing.JComponent;
import javax.swing.JFrame;

public class Testing2D {
   public static void main(String[] args) {
       TestF1 test=new TestF1();
       test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       test.setVisible(true);
   }

}

/**
* 构造窗口的初始化时的大小
* @author Administrator
*
*/
class TestF1 extends JFrame
{
public TestF1()
{
    setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
    TestF2  test=new TestF2();
    test.setForeground(SystemColor.window);
    add(test);
}    
public static final int DEFAULT_WIDTH=300;
public static final int DEFAULT_HEIGHT=300;
}

/**
*构造Graphics2D功能
* @author Administrator
*
*/
class TestF2 extends JComponent
{

     public void paintComponent(Graphics g)
     {
         Graphics2D g2=(Graphics2D)g;//将该功能转换为2D的功能

         /**
          * 实例化一个椭圆的对象
          */
         Ellipse2D.Float test2D=new Ellipse2D.Float(100.0f,100.0f,300.0f,600.0f);//第1/2个参数是表示左上角的位置,3/4表示宽和高
         Rectangle2D.Float test2Ddd=new Rectangle2D.Float(300.0f,100.0f,30.0f,300.0f);
         Ellipse2D.Float test2Dd=new Ellipse2D.Float(200.0f,200.0f,50.0f,50.0f);
         Point2D test2Df=new Point2D.Double(10,20);
         Line2D test=new Line2D.Float(12.0f,13.0f, 250.0f, 16.0f);
         /**
          * 将这个对象用2D方法画出来
          */


         //g2.draw(test2Df);
         g2.setPaint(Color.RED);
         g2.draw(test);
         g2.draw(test2Ddd);
         g2.draw(test2D);
         g2.fill(test2Ddd);//填充颜色
         g2.draw(test2Dd);
     }
}