| java.lang.Object java.awt.Polygon
Polygon | public class Polygon implements Shape,java.io.Serializable(Code) | | 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 (x, y) 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 (x, y)
points are joined by a line segment that closes the polygon.
version: 1.18, 07/01/98 author: Sami Shaio author: Herb Jellinek since: JDK1.0 |
Constructor Summary | |
public | Polygon() Creates an empty polygon. | public | Polygon(int xpoints, int ypoints, int npoints) Constructs and initializes a polygon from the specified
parameters. |
Method Summary | |
public void | addPoint(int x, int y) Appends a point to this polygon. | void | calculateBounds(int xpoints, int ypoints, int npoints) | public boolean | contains(Point p) Determines whether the specified point is inside the Polygon. | public boolean | contains(int x, int y) Determines whether the specified point is contained by this polygon. | public Rectangle | getBoundingBox() | public Rectangle | getBounds() Gets the bounding box of this polygon. | public boolean | inside(int x, int y) | public void | invalidate() Invalidates or flushes any internally-cached data that depends
on the vertex coordinates of this Polygon . | public void | reset() Resets this Polygon object to an empty polygon. | public void | translate(int deltaX, int deltaY) Translates the vertices by deltaX along the
x axis and by deltaY along the
y axis. | void | updateBounds(int x, int y) |
npoints | public int npoints(Code) | | The total number of points.
since: JDK1.0 |
xpoints | public int xpoints(Code) | | The array of x coordinates.
since: JDK1.0 |
ypoints | public int ypoints(Code) | | The array of y coordinates.
since: JDK1.0 |
Polygon | public Polygon()(Code) | | Creates an empty polygon.
since: JDK1.0 |
Polygon | public Polygon(int xpoints, int ypoints, int npoints)(Code) | | Constructs and initializes a polygon from the specified
parameters.
Parameters: xpoints - an array of x coordinates. Parameters: ypoints - an array of y coordinates. Parameters: npoints - the total number of points in the polygon. exception: NegativeArraySizeException - if the value ofnpoints is negative. since: JDK1.0 |
addPoint | public void addPoint(int x, int y)(Code) | | 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. Parameters: y - the y coordinate of the point. See Also: java.awt.Polygon.getBounds See Also: java.awt.Polygon.contains since: JDK1.0 |
calculateBounds | void calculateBounds(int xpoints, int ypoints, int npoints)(Code) | | |
contains | public boolean contains(Point p)(Code) | | 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 |
contains | public boolean contains(int x, int y)(Code) | | Determines whether the specified point is contained by this polygon.
Parameters: x - the x coordinate of the point to be tested. Parameters: y - the y coordinate of the point to be tested. true if the point (x, y) is contained by this polygon; false otherwise. since: JDK1.1 |
getBounds | public Rectangle getBounds()(Code) | | 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.
a rectangle that defines the bounds of this polygon. since: JDK1.1 |
inside | public boolean inside(int x, int y)(Code) | | |
invalidate | public void invalidate()(Code) | | Invalidates or flushes any internally-cached data that depends
on the vertex coordinates of this Polygon .
This method should be called after any direct manipulation
of the coordinates in the xpoints or
ypoints arrays to avoid inconsistent results
from methods such as getBounds or contains
that might cache data from earlier computations relating to
the vertex coordinates.
See Also: java.awt.Polygon.getBounds since: 1.4 |
reset | public void reset()(Code) | | Resets this Polygon object to an empty polygon.
The coordinate arrays and the data in them are left untouched
but the number of points is reset to zero to mark the old
vertex data as invalid and to start accumulating new vertex
data at the beginning.
All internally-cached data relating to the old vertices
are discarded.
Note that since the coordinate arrays from before the reset
are reused, creating a new empty Polygon might
be more memory efficient than resetting the current one if
the number of vertices in the new polygon data is significantly
smaller than the number of vertices in the data from before the
reset.
See Also: java.awt.Polygon.invalidate since: 1.4 |
translate | public void translate(int deltaX, int deltaY)(Code) | | 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 Parameters: deltaY - the amount to translate along the y axis since: JDK1.1 |
updateBounds | void updateBounds(int x, int y)(Code) | | |
|
|