Arc2D arc=new Arc2D.Double(0,0,100,100,-90,-180,Arc2D.PIE); arc.setArc(0,0,100,100,-90,180,Arc2D.PIE);
Ellipse2D ellipse=new Ellipse2D.Double(40,15,20,20); ellipse.setFrame(40,65,30,30);
Graphics2D g_2d=(Graphics2D)g; g_2d.setColor(Color.magenta); g_2d.fill(ellipse); g_2d.fill(arc);
g.setColor(Color.GREEN); Polygon polygon=new Polygon(); polygon.addPoint(100,10); polygon.addPoint(110,90); polygon.addPoint(210,90); polygon.addPoint(200,10); g_2d.draw(polygon);
import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;
class MyCanvas extends JPanel{
public void paint(Graphics g){
Graphics2D g_2d=(Graphics2D)g;
Arc2D arc=new Arc2D.Double(0,0,100,100,-90,-180,Arc2D.PIE);//1
g_2d.setColor(Color.black);
g_2d.fill(arc);
g_2d.setColor(Color.white);//2
arc.setArc(0,0,100,100,-90,180,Arc2D.PIE);
g_2d.fill(arc);
arc.setArc(25,0,50,50,-90,-180,Arc2D.PIE);//3
g_2d.fill(arc);
g_2d.setColor(Color.black);//4
arc.setArc(25,50,50,50,90,-180,Arc2D.PIE);
g_2d.fill(arc);
Ellipse2D ellipse=new Ellipse2D.Double(40,15,20,20);//5
g_2d.fill(ellipse);
g_2d.setColor(Color.magenta);//6
ellipse.setFrame(40,65,30,30);
g_2d.fill(ellipse);
g.setColor(Color.GREEN);//7
Polygon polygon=new Polygon();
polygon.addPoint(100,10);
polygon.addPoint(110,90);
polygon.addPoint(210,90);
polygon.addPoint(200,10);
g_2d.draw(polygon);
}
}
public class Main{
public static void main(String argas[]){
JFrame win = new JFrame();
win.setSize(400,200);
win.add(new MyCanvas());
win.setVisible(true);
}
}
这里,g 和 g_2d,都可用 ,but why????
import
abstract void |
setArc(double x, double y, double w, double h, double angSt, double angExt, int closure) 将此弧的位置、大小、角度范围和闭合类型设置为指定的双精度值。 |