介绍

The Arc2D class is the superclass for all objects that store a 2D arc defined by a framing rectangle, start angle, angular extent (length of the arc), and a closure type (OPEN, CHORD, or PIE).

类声明

Following is the declaration for java.awt.Arc2D class:

public abstract class Arc2D   extends RectangularShape

Field

Following are the fields for java.awt.geom.Arc2D class:

• static int CHORD — The closure type for an arc closed by drawing a straight line segment from the start of the arc segment to the end of the arc segment.

• static int OPEN — The closure type for an open arc with no path segments connecting the two ends of the arc segment.

• static int PIE — The closure type for an arc closed by drawing straight line segments from the start of the arc segment to the center of the full ellipse and from that point to the end of the arc segment.

类的构造函数

S.N.Constructor & Description
1protected Arc2D(int type) This is an abstract class that cannot be instantiated directly.

类方法

S.N.Method & Description
1boolean contains(double x, double y) Determines whether or not the specified point is inside the boundary of the arc.
2boolean contains(double x, double y, double w, double h) Determines whether or not the interior of the arc entirely contains the specified rectangle.
3boolean contains(Rectangle2D r) Determines whether or not the interior of the arc entirely contains the specified rectangle.
4boolean containsAngle(double angle) Determines whether or not the specified angle is within the angular extents of the arc.
5boolean equals(Object obj) Determines whether or not the specified Object is equal to this Arc2D.
6abstract double getAngleExtent() Returns the angular extent of the arc.
7abstract double getAngleStart() Returns the starting angle of the arc.
8int getArcType() Returns the arc closure type of the arc: OPEN, CHORD, or PIE.
9Rectangle2D getBounds2D() Returns the high-precision framing rectangle of the arc.
10Point2D getEndPoint() Returns the ending point of the arc.
11PathIterator getPathIterator(AffineTransform at) Returns an iteration object that defines the boundary of the arc.
12Point2D getStartPoint() Returns the starting point of the arc.
13int hashCode() Returns the hashcode for this Arc2D.
14boolean intersects(double x, double y, double w, double h) Determines whether or not the interior of the arc intersects the interior of the specified rectangle.
15protected abstract Rectangle2DmakeBounds(double x, double y, double w, double h) Constructs a Rectangle2D of the appropriate precision to hold the parameters calculated to be the framing rectangle of this arc.
16abstract void setAngleExtent(double angExt) Sets the angular extent of this arc to the specified double value.
17void setAngles(double x1, double y1, double x2, double y2) Sets the starting angle and angular extent of this arc using two sets of coordinates.
18void setAngles(Point2D p1, Point2D p2) Sets the starting angle and angular extent of this arc using two points.
19abstract void setAngleStart(double angSt) Sets the starting angle of this arc to the specified double value.
20void setAngleStart(Point2D p) Sets the starting angle of this arc to the angle that the specified point defines relative to the center of this arc.
21void setArc(Arc2D a) Sets this arc to be the same as the specified arc.
22abstract void setArc(double x, double y, double w, double h, double angSt, double angExt, int closure) Sets the location, size, angular extents, and closure type of this arc to the specified double values.
23void setArc(Point2D loc, Dimension2D size, double angSt, double angExt, int closure) Sets the location, size, angular extents, and closure type of this arc to the specified values.
24void setArc(Rectangle2D rect, double angSt, double angExt, int closure) Sets the location, size, angular extents, and closure type of this arc to the specified values.
25void setArcByCenter(double x, double y, double radius, double angSt, double angExt, int closure) Sets the position, bounds, angular extents, and closure type of this arc to the specified values.
26void setArcByTangent(Point2D p1, Point2D p2, Point2D p3, double radius) Sets the position, bounds, and angular extents of this arc to the specified value.
27void setArcType(int type) Sets the closure type of this arc to the specified value: OPEN, CHORD, or PIE.
28void setFrame(double x, double y, double w, double h) Sets the location and size of the framing rectangle of this Shape to the specified rectangular values.

方法继承

This class inherits methods from the following classes:

• java.awt.geom.RectangularShape

• java.lang.Object

Arc2D Example

Create the following java program using any editor of your choice in say D:/ > AWT > com > tutorialspoint > gui >AWTGraphicsDemo.java

package com.tutorialspoint.gui; import java.awt.*;import java.awt.event.*;import java.awt.geom.*; public class AWTGraphicsDemo extends Frame {    public AWTGraphicsDemo(){      super("Java AWT Examples");      prepareGUI();   }    public static void main(String[] args){      AWTGraphicsDemo  awtGraphicsDemo = new AWTGraphicsDemo();        awtGraphicsDemo.setVisible(true);   }    private void prepareGUI(){      setSize(400,400);      addWindowListener(new WindowAdapter() {         public void windowClosing(WindowEvent windowEvent){            System.exit(0);         }              });    }        @Override   public void paint(Graphics g) {      Arc2D.Float arc = new Arc2D.Float(Arc2D.PIE);      arc.setFrame(70, 200, 150, 150);      arc.setAngleStart(0);      arc.setAngleExtent(145);      Graphics2D g2 = (Graphics2D) g;       g2.setColor(Color.gray);      g2.draw(arc);      g2.setColor(Color.red);      g2.fill(arc);      g2.setColor(Color.black);      Font font = new Font("Serif", Font.PLAIN, 24);      g2.setFont(font);      g.drawString("Welcome to TutorialsPoint", 50, 70);      g2.drawString("Arc2D.PIE", 100, 120);    }}

Compile the program using command prompt. Go to D:/ > AWT and type the following command.

D:\AWT>javac com\tutorialspoint\gui\AwtGraphicsDemo.java

If no error comes that means compilation is successful. Run the program using following command.

D:\AWT>java com.tutorialspoint.gui.AwtGraphicsDemo

Verify the following output