Line2D的類宣告線段(X,Y)坐標空間。
以下是宣告java.awt.geom.Line2D類:
public abstract class Line2D extends Object implements Shape, Cloneable
S.N. | 建構函式與說明 |
---|---|
1 |
protected Line2D() () This is an abstract class that cannot be instantiated directly. |
S.N. | 方法和說明 |
---|---|
1 |
Object clone() Creates a new object of the same class as this object. |
2 |
boolean contains(double x, double y) Tests if a specified coordinate is inside the boundary of this Line2D. |
3 |
boolean contains(double x, double y, double w, double h) Tests if the interior of this Line2D entirely contains the specified set of rectangular coordinates. |
4 |
boolean contains(Point2D p) Tests if a given Point2D is inside the boundary of this Line2D. |
5 |
boolean contains(Rectangle2D r) Tests if the interior of this Line2D entirely contains the specified Rectangle2D. |
6 |
Rectangle getBounds() Returns an integer Rectangle that completely encloses the Shape. |
7 |
abstract Point2D getP1() Returns the start Point2D of this Line2D. |
8 |
abstract Point2D getP2() Returns the end Point2D of this Line2D. |
9 |
PathIterator getPathIterator(AffineTransform at) Returns an iteration object that defines the boundary of this Line2D. |
10 |
PathIterator getPathIterator(AffineTransform at, double flatness) Returns an iteration object that defines the boundary of this flattened Line2D. |
11 |
abstract double getX1() Returns the X coordinate of the start point in double precision. |
12 |
abstract double getX2() Returns the X coordinate of the end point in double precision. |
13 |
abstract double getY1() Returns the Y coordinate of the start point in double precision. |
14 |
abstract double getY2() Returns the Y coordinate of the end point in double precision. |
15 |
boolean intersects(double x, double y, double w, double h) Tests if the interior of the Shape intersects the interior of a specified rectangular area. |
16 |
boolean intersects(Rectangle2D r) Tests if the interior of the Shape intersects the interior of a specified Rectangle2D. |
17 |
boolean intersectsLine(double x1, double y1, double x2, double y2) Tests if the line segment from (x1,y1) to (x2,y2) intersects this line segment. |
18 |
boolean intersectsLine(Line2D l) Tests if the specified line segment intersects this line segment. |
19 |
static boolean linesIntersect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) Tests if the line segment from (x1,y1) to (x2,y2) intersects the line segment from (x3,y3) to (x4,y4). |
20 |
double ptLineDist(double px, double py) Returns the distance from a point to this line. |
21 |
static double ptLineDist(double x1, double y1, double x2, double y2, double px, double py) Returns the distance from a point to a line. |
22 |
double ptLineDist(Point2D pt) Returns the distance from a Point2D to this line. |
23 |
double ptLineDistSq(double px, double py) Returns the square of the distance from a point to this line. |
24 |
static double ptLineDistSq(double x1, double y1, double x2, double y2, double px, double py) Returns the square of the distance from a point to a line. |
25 |
double ptLineDistSq(Point2D pt) Returns the square of the distance from a specified Point2D to this line. |
26 |
double ptSegDist(double px, double py) Returns the distance from a point to this line segment. |
27 |
static double ptSegDist(double x1, double y1, double x2, double y2, double px, double py) Returns the distance from a point to a line segment. |
28 |
double ptSegDist(Point2D pt) Returns the distance from a Point2D to this line segment. |
29 |
double ptSegDistSq(double px, double py) Returns the square of the distance from a point to this line segment. |
30 |
static double ptSegDistSq(double x1, double y1, double x2, double y2, double px, double py) Returns the square of the distance from a point to a line segment. |
31 |
double ptSegDistSq(Point2D pt) Returns the square of the distance from a Point2D to this line segment. |
32 |
int relativeCCW(double px, double py) Returns an indicator of where the specified point (px,py) lies with respect to this line segment. |
33 |
static int relativeCCW(double x1, double y1, double x2, double y2, double px, double py) Returns an indicator of where the specified point (px,py) lies with respect to the line segment from (x1,y1) to (x2,y2). |
34 |
int relativeCCW(Point2D p) Returns an indicator of where the specified Point2D lies with respect to this line segment. |
35 |
abstract void setLine(double x1, double y1, double x2, double y2) Sets the location of the end points of this Line2D to the specified double coordinates. |
36 |
void setLine(Line2D l) Sets the location of the end points of this Line2D to the same as those end points of the specified Line2D. |
37 |
void setLine(Point2D p1, Point2D p2) Sets the location of the end points of this Line2D to the specified Point2D coordinates. |
這個類繼承的方法從以下類:
java.lang.Object
選擇使用任何編輯器建立以下java程式D:/ > AWT > com > yiibai > gui >
AWTGraphicsDemo.javapackage 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) { Line2D shape = new Line2D.Double(); shape.setLine(250D,250D,150D,150D); Graphics2D g2 = (Graphics2D) g; g2.draw (shape); Font font = new Font("Serif", Font.PLAIN, 24); g2.setFont(font); g.drawString("Welcome to TutorialsPoint", 50, 70); g2.drawString("Line2D.Line", 100, 120); } }
編譯程式,使用命令提示字元。進入到D:/> AWT,然後鍵入以下命令。
D:AWT>javac comyiibaiguiAWTGraphicsDemo.java
如果沒有錯誤出現,這意味著編譯成功。使用下面的命令來執行程式。
D:AWT>java com.yiibai.gui.AWTGraphicsDemo
驗證下面的輸出