站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > JDK 5 Documentation v1.1.8, Java 2 SDK 英文文档

Class java.awt.Polygon - JDK 5 Documentation v1.1.8, Java 2 SDK 英文文档

All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class java.awt.Polygon

java.lang.Object
   |
   +----java.awt.Polygon

public class Polygon
extends Object
implements Shape, Serializable
The Polygon class encapsulates a description of a closed, two-dimensional region within a coordinate space. This region is bounded by an arbitrary number of line segments, each of which is one side of the polygon. Internally, a polygon comprises of a list of (xy) coordinate pairs, where each pair defines a vertex of the polygon, and two successive pairs are the endpoints of a line that is a side of the polygon. The first and final pairs of (xy) points are joined by a line segment that closes the polygon.


Variable Index

 o bounds
 o npoints
The total number of points.
 o xpoints
The array of x coordinates.
 o ypoints
The array of y coordinates.

Constructor Index

 o Polygon()
Creates an empty polygon.
 o Polygon(int[], int[], int)
Constructs and initializes a polygon from the specified parameters.

Method Index

 o addPoint(int, int)
Appends a point to this polygon.
 o contains(int, int)
Determines whether the specified point is contained by this polygon.
 o contains(Point)
Determines whether the specified point is inside the Polygon.
 o getBoundingBox()
Deprecated.
 o getBounds()
Gets the bounding box of this polygon.
 o inside(int, int)
Deprecated.
 o translate(int, int)
Translates the vertices by deltaX along the x axis and by deltaY along the y axis.

Variables

 o npoints
 public int npoints
The total number of points.

 o xpoints
 public int xpoints[]
The array of x coordinates.

 o ypoints
 public int ypoints[]
The array of y coordinates.

 o bounds
 protected Rectangle bounds

Constructors

 o Polygon
 public Polygon()
Creates an empty polygon.

 o Polygon
 public Polygon(int xpoints[],
                int ypoints[],
                int npoints)
Constructs and initializes a polygon from the specified parameters.

Parameters:
xpoints - an array of x coordinates.
ypoints - an array of y coordinates.
npoints - the total number of points in the polygon.
Throws: NegativeArraySizeException
if the value of npoints is negative.

Methods

 o translate
 public void translate(int deltaX,
                       int deltaY)
Translates the vertices by deltaX along the x axis and by deltaY along the y axis.

Parameters:
deltaX - the amount to translate along the x axis
deltaY - the amount to translate along the y axis
 o addPoint
 public void addPoint(int x,
                      int y)
Appends a point to this polygon.

If an operation that calculates the bounding box of this polygon has already been performed, such as getBounds or contains, then this method updates the bounding box.

Parameters:
x - the x coordinate of the point.
y - the y coordinate of the point.
See Also:
getBounds, contains
 o getBounds
 public Rectangle getBounds()
Gets the bounding box of this polygon. The bounding box is the smallest rectangle whose sides are parallel to the x and y axes of the coordinate space, and that can completely contain the polygon.

Returns:
a rectangle that defines the bounds of this polygon.
 o getBoundingBox
 public Rectangle getBoundingBox()
Note: getBoundingBox() is deprecated. As of JDK version 1.1, replaced by getBounds().

 o contains
 public boolean contains(Point p)
Determines whether the specified point is inside the Polygon. Uses an even-odd insideness rule (also known as an alternating rule).

Parameters:
p - the point to be tested
 o contains
 public boolean contains(int x,
                         int y)
Determines whether the specified point is contained by this polygon.

(The contains method is based on code by Hanpeter van Vliet [hvvliet@inter.nl.net].)

Parameters:
x - the x coordinate of the point to be tested.
y - the y coordinate of the point to be tested.
Returns:
true if the point (xy) is contained by this polygon; false otherwise.
 o inside
 public boolean inside(int x,
                       int y)
Note: inside() is deprecated. As of JDK version 1.1, replaced by contains(int, int).


All Packages  Class Hierarchy  This Package  Previous  Next  Index

Submit a bug or feature - Version 1.1.8 of Java Platform API Specification
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1995-1999 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.