public class Polygon
extends java.awt.Polygon
java.awt.Polygon
.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CIRCLE
Constants for circle type.
|
static java.lang.String |
POLY
Constants for polygon type.
|
static java.lang.String |
RECTANGLE
Constants for rectangle type.
|
Constructor and Description |
---|
Polygon()
Creates an empty polygon.
|
Polygon(int[] xpoints,
int[] ypoints,
int npoints)
Constructs and initializes a
Polygon from the specified parameters. |
Polygon(int[] xpoints,
int[] ypoints,
int npoints,
java.lang.String preferedShape)
Constructs and initializes a
Polygon from the specified parameters. |
Polygon(java.lang.String preferedShape)
Creates an empty polygon with preferred shape.
|
Modifier and Type | Method and Description |
---|---|
Point |
getPoint(int pos)
Return coordinate of point at position.
|
java.util.List<Point> |
getPointList()
Return
List of point in this shape. |
java.lang.String |
getPreferedShape()
Return a preferedShape.
|
Rectangle |
getRectangle()
Gets the bounding box of this
Polygon . |
int |
getTotalPoint()
Return total number of points.
|
void |
setPreferedShape(java.lang.String preferedShape)
Set a preferedShape.
|
java.lang.String |
toString()
Returns a string representation of the object.
|
public static final java.lang.String RECTANGLE
public static final java.lang.String CIRCLE
public static final java.lang.String POLY
public Polygon()
public Polygon(java.lang.String preferedShape)
preferedShape
- preferred shapepublic Polygon(int[] xpoints, int[] ypoints, int npoints)
Polygon
from the specified parameters.xpoints
- an array of x coordinatesypoints
- an array of y coordinatesnpoints
- the total number of points in the Polygon
java.lang.NegativeArraySizeException
- if the value of npoints
is negative.java.lang.IndexOutOfBoundsException
- if npoints
is greater than the length of
xpoints
or the length of ypoints
.java.lang.NullPointerException
- if xpoints
or ypoints
is null
.public Polygon(int[] xpoints, int[] ypoints, int npoints, java.lang.String preferedShape)
Polygon
from the specified parameters.xpoints
- an array of x coordinatesypoints
- an array of y coordinatesnpoints
- the total number of points in the Polygon
preferedShape
- preferred shapejava.lang.NegativeArraySizeException
- if the value of npoints
is negative.java.lang.IndexOutOfBoundsException
- if npoints
is greater than the length of
xpoints
or the length of ypoints
.java.lang.NullPointerException
- if xpoints
or ypoints
is null
.public Point getPoint(int pos)
pos
- positionpublic int getTotalPoint()
public java.util.List<Point> getPointList()
List
of point in this shape.List
of pointpublic java.lang.String getPreferedShape()
public void setPreferedShape(java.lang.String preferedShape)
preferedShape
- the preferedShape to setpublic Rectangle getRectangle()
Polygon
. The bounding box is the smallest Rectangle
whose sides are parallel to the x and y axes of the coordinate space, and can completely contain the
Polygon
.Rectangle
that defines the bounds of this Polygon
.public java.lang.String toString()
toString
in class java.lang.Object