|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object acm.graphics.GObject acm.graphics.GPolygon
public class GPolygon
The GPolygon
class is a graphical object whose appearance consists
of a polygon.
Constructor Summary | |
---|---|
GPolygon()
Constructs a new empty polygon at the origin. |
|
GPolygon(double x,
double y)
Constructs a new empty polygon at ( x , y ). |
|
GPolygon(GPoint[] points)
Constructs a new polygon from the specified array of GPoint
objects. |
Method Summary | |
---|---|
void |
addArc(double arcWidth,
double arcHeight,
double start,
double sweep)
Adds a series of edges to the polygon that simulates the arc specified by the parameters. |
void |
addEdge(double dx,
double dy)
Adds an edge to the polygon whose components are given by the displacements dx and dy from the last vertex. |
void |
addPolarEdge(double r,
double theta)
Adds an edge to the polygon specified in polar coordinates. |
void |
addVertex(double x,
double y)
Adds a vertex at ( x , y ) relative to the polygon origin. |
protected void |
clear()
Calling this method deletes all vertices from the polygon and resets the scale and rotation factors to the their default values. |
Object |
clone()
Overrides clone in Object to make sure
that the vertex list is copied rather than shared. |
boolean |
contains(double x,
double y)
Checks to see whether a point is inside the object. |
GRectangle |
getBounds()
Returns the bounding box of this object, which is defined to be the smallest rectangle that covers everything drawn by the figure. |
GPoint |
getCurrentPoint()
Returns the coordinates of the last vertex added to the polygon, or null
if the polygon is empty. |
Color |
getFillColor()
Returns the color used to display the filled region of this object. |
protected Polygon |
getPolygon()
Returns an AWT Polygon whose points are as close as possible
to the ones in this GPolygon . |
boolean |
isFilled()
Returns whether this object is filled. |
protected void |
markAsComplete()
Calling this method makes it illegal to add or remove vertices from the polygon. |
void |
paint(Graphics g)
Implements the paint operation for this graphical object. |
void |
recenter()
Recalculates the vertices of the polygon so that they are positioned relative to the geometric center of the object. |
protected void |
repaint()
Overrides repaint in GObject to invalidate the
cached polygon. |
void |
rotate(double theta)
Rotates the polygon around its origin by the angle theta, measured in degrees. |
void |
scale(double sf)
Scales the object on the screen by the scale factor sf , which applies
in both dimensions. |
void |
scale(double sx,
double sy)
Scales the polygon by the scale factors sx and sy . |
void |
setFillColor(Color color)
Sets the color used to display the filled region of this object. |
void |
setFilled(boolean fill)
Sets whether this object is filled. |
Methods inherited from class acm.graphics.GObject |
---|
addActionListener, addMouseListener, addMouseMotionListener, areMouseListenersEnabled, colorName, contains, fireActionEvent, fireActionEvent, fireMouseListeners, getColor, getComponent, getHeight, getLocation, getObjectColor, getParent, getSize, getWidth, getX, getY, isVisible, move, movePolar, paintObject, paramString, pause, removeActionListener, removeMouseListener, removeMouseMotionListener, sendBackward, sendForward, sendToBack, sendToFront, setColor, setLocation, setLocation, setParent, setVisible, start, start, toString, updateEnabledList |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public GPolygon()
public GPolygon(double x, double y)
x
, y
).
x
- The x-coordinate of the origin of the polygony
- The y-coordinate of the origin of the polygonpublic GPolygon(GPoint[] points)
GPoint
objects. The polygon is automatically marked as complete.
points
- An array of GPoint
objects specifying the verticesMethod Detail |
---|
public void addArc(double arcWidth, double arcHeight, double start, double sweep)
arcWidth
- The width of the oval from which the arc is takenarcHeight
- The height of the oval from which the arc is takenstart
- The angle at which the arc beginssweep
- The extent of the arcpublic void addEdge(double dx, double dy)
dx
and dy
from the last vertex.
dx
- The x displacement through which the edge movesdy
- The y displacement through which the edge movespublic final void addPolarEdge(double r, double theta)
r
, and the edge extends in direction theta
,
measured in degrees counterclockwise from the +x axis.
r
- The length of the edgetheta
- The angle at which the edge extends measured in degreespublic void addVertex(double x, double y)
x
, y
) relative to the polygon origin.
x
- The x-coordinate of the vertex relative to the polygon originy
- The y-coordinate of the vertex relative to the polygon originprotected void clear()
public Object clone()
clone
in Object
to make sure
that the vertex list is copied rather than shared.
clone
in class Object
public boolean contains(double x, double y)
contains
in class GObject
x
- The x-coordinate of the point being testedy
- The y-coordinate of the point being tested
true
if the point (x
, y
) is inside
the object, and false
otherwisepublic GRectangle getBounds()
getBounds
in class GObject
public GPoint getCurrentPoint()
null
if the polygon is empty.
null
if emptypublic Color getFillColor()
getFillColor
returns the color of the
object.
getFillColor
in interface GFillable
protected Polygon getPolygon()
Polygon
whose points are as close as possible
to the ones in this GPolygon
.
public boolean isFilled()
isFilled
in interface GFillable
protected void markAsComplete()
public void paint(Graphics g)
paint
operation for this graphical object. This method
is not called directly by clients.
paint
in class GObject
g
- The graphics context into which the painting is donepublic void recenter()
protected void repaint()
repaint
in GObject
to invalidate the
cached polygon.
repaint
in class GObject
public void rotate(double theta)
theta
- The angle of rotation in degrees counterclockwisepublic final void scale(double sf)
sf
, which applies
in both dimensions.
scale
in interface GScalable
sf
- The factor used to scale all coordinates in both dimensionspublic void scale(double sx, double sy)
sx
and sy
.
scale
in interface GScalable
sx
- The factor used to scale all coordinates in the x directionsy
- The factor used to scale all coordinates in the y directionpublic void setFillColor(Color color)
setFillColor
in interface GFillable
color
- The color used to display the filled region of this objectpublic void setFilled(boolean fill)
setFilled
in interface GFillable
fill
- true
if the object should be filled, false
for an outline
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |