graphics
Class Polygon

java.lang.Object
  extended by graphics.AbstractGraphic
      extended by graphics.AbstractColorableGraphic
          extended by graphics.Polygon
All Implemented Interfaces:
CenterLocatable, IColorable, IColorableGraphic, IGraphic, ILocatable, IRotatable, ISizeable
Direct Known Subclasses:
BouncingTriangle

public class Polygon
extends AbstractColorableGraphic

A polygon is a Graphic that can form many shapes. To use, first set the desired dimension of the polygon. Then add at least three points in order to correctly make a polygon. This will then play connect the dots in the order that the points were added. Then connects the last point back to the first, forming a polygon.

For example, to create a triangle:
graphics.Polygon triangle = new graphics.Polygon();
_triangle.setDimension(new java.awt.Dimension(30,30));
_triangle.addPoint(new Point(0,0));
_triangle.addPoint(new Point(30,0));
_triangle.addPoint(new Point(30,30));

Author:
Michael Kozelsky Created on: Jul 29, 2006 Polygon.java

Constructor Summary
Polygon()
          Creates a new instance of Polygon with no vertices
 
Method Summary
 void actualPaint(Graphics2D gs, Point location, Dimension dimension)
          This method uses the Graphics2D object to paint the Polygon onto the container.
 void addPoint(Point p)
          Add a point to the polygon
 Shape getShape()
          Gets a java.awt.shape that represents this shape
 void removePoint(Point p)
          removes the first occurrence of point p from the polygon
 void setDimension(Dimension d)
          Resizes the Polygon to a specified dimension.
 void setLocation(Point point)
          Sets the upper left hand corner of the polygon's bounding box.
 
Methods inherited from class graphics.AbstractColorableGraphic
getColor, paint, setColor
 
Methods inherited from class graphics.AbstractGraphic
addMouseListener, addMouseMotionListener, contains, getBounds, getCenterLocation, getContainer, getDimension, getLocation, getMouseListeners, getMouseMotionListeners, getMovement, getRotation, intersects, move, rotate, setCenterLocation, setContainer, setMovement, setRotation
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface graphics.IGraphic
addMouseListener, addMouseMotionListener, contains, getBounds, getContainer, getMouseListeners, getMouseMotionListeners, getMovement, intersects, setContainer, setMovement
 
Methods inherited from interface graphics.ISizeable
getDimension
 
Methods inherited from interface graphics.CenterLocatable
getCenterLocation, setCenterLocation
 
Methods inherited from interface graphics.ILocatable
getLocation, move
 
Methods inherited from interface graphics.IRotatable
getRotation, rotate, setRotation
 

Constructor Detail

Polygon

public Polygon()
Creates a new instance of Polygon with no vertices

Method Detail

addPoint

public void addPoint(Point p)
Add a point to the polygon

Parameters:
p - the point to add

removePoint

public void removePoint(Point p)
removes the first occurrence of point p from the polygon

Parameters:
p - The Point to remove

actualPaint

public void actualPaint(Graphics2D gs,
                        Point location,
                        Dimension dimension)
This method uses the Graphics2D object to paint the Polygon onto the container. The location and dimension parameters are not used because the polygon knows it's location and dimension

Parameters:
gs - The Graphics2D object to do the painting
location - Does nothing
dimension - Does Nothing
See Also:
IGraphic.actualPaint(java.awt.Graphics2D, java.awt.Point, java.awt.Dimension)

setLocation

public void setLocation(Point point)
Sets the upper left hand corner of the polygon's bounding box.

Specified by:
setLocation in interface ILocatable
Overrides:
setLocation in class AbstractGraphic
Parameters:
point - A java.awt.Point representing the new location of the Polygon
See Also:
ILocatable.setLocation(java.awt.Point)

setDimension

public void setDimension(Dimension d)
Resizes the Polygon to a specified dimension.

Specified by:
setDimension in interface ISizeable
Overrides:
setDimension in class AbstractGraphic
Parameters:
d - The dimension which the polygon should have
See Also:
ISizeable.setDimension(java.awt.Dimension)

getShape

public Shape getShape()
Gets a java.awt.shape that represents this shape

Returns:
a java.awt.Polygon that represents this polygon
See Also:
IGraphic.getShape()