AWT Arc2D類


Arc2D類是父類別的所有物件儲存框架矩形定義一個二維弧,開始角度,稜角分明的程度(弧長),和一個閉合型(OPEN,CHORD或PIE)。

類的宣告

以下是的宣告類java.awt.Arc2D:

public abstract class Arc2D
   extends RectangularShape

欄位域

以下是java.awt.geom.Arc2D類的欄位:

  • static int CHORD -- 關閉的圓弧的閉合型別針對通過從弧段的弧段的開始到結束的直線段。

  • static int OPEN -- 該閉合型別沒有路徑段連線的圓弧段的兩端開口弧。

  • static int PIE -- 關閉的圓弧的閉合型別針對通過繪製完整橢圓的中心的圓弧段,從一開始,從該點的直線段,圓弧段的結束。

類別建構函式

S.N. 建構函式與說明
1 protected Arc2D(int type) 
This is an abstract class that cannot be instantiated directly.

類方法

S.N. 方法和說明
1 boolean contains(double x, double y) 
Determines whether or not the specified point is inside the boundary of the arc.
2 boolean contains(double x, double y, double w, double h) 
Determines whether or not the interior of the arc entirely contains the specified rectangle.
3 boolean contains(Rectangle2D r) 
Determines whether or not the interior of the arc entirely contains the specified rectangle.
4 boolean containsAngle(double angle) 
Determines whether or not the specified angle is within the angular extents of the arc.
5 boolean equals(Object obj) 
Determines whether or not the specified Object is equal to this Arc2D.
6 abstract double getAngleExtent() 
Returns the angular extent of the arc.
7 abstract double getAngleStart() 
Returns the starting angle of the arc.
8 int getArcType() 
Returns the arc closure type of the arc: OPEN, CHORD, or PIE.
9 Rectangle2D getBounds2D() 
Returns the high-precision framing rectangle of the arc.
10 Point2D getEndPoint() 
Returns the ending point of the arc.
11 PathIterator getPathIterator(AffineTransform at) 
Returns an iteration object that defines the boundary of the arc.
12 Point2D getStartPoint() 
Returns the starting point of the arc.
13 int hashCode() 
Returns the hashcode for this Arc2D.
14 boolean 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.
15 protected abstract Rectangle2D makeBounds(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.
16 abstract void setAngleExtent(double angExt) 
Sets the angular extent of this arc to the specified double value.
17 void setAngles(double x1, double y1, double x2, double y2) 
Sets the starting angle and angular extent of this arc using two sets of coordinates.
18 void setAngles(Point2D p1, Point2D p2) 
Sets the starting angle and angular extent of this arc using two points.
19 abstract void setAngleStart(double angSt) 
Sets the starting angle of this arc to the specified double value.
20 void 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.
21 void setArc(Arc2D a) 
Sets this arc to be the same as the specified arc.
22 abstract 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.
23 void 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.
24 void 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.
25 void 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.
26 void setArcByTangent(Point2D p1, Point2D p2, Point2D p3, double radius) 
Sets the position, bounds, and angular extents of this arc to the specified value.
27 void setArcType(int type) 
Sets the closure type of this arc to the specified value: OPEN, CHORD, or PIE.
28 void 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.

繼承的方法

這個類繼承的方法從以下類:

  • java.awt.geom.RectangularShape

  • java.lang.Object

Arc2D 範例

選擇使用任何編輯器建立以下java程式 D:/ > AWT > com > yiibai > gui >

AWTGraphicsDemo.java
package com.yiibai.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); 
   }
}

編譯程式,使用命令提示字元。進入到D:/> AWT,然後鍵入以下命令。

D:AWT>javac comyiibaiguiAwtGraphicsDemo.java

如果沒有錯誤出現,這意味著編譯成功。使用下面的命令來執行程式。

D:AWT>java com.yiibai.gui.AwtGraphicsDemo

驗證下面的輸出

AWT Arc2D