Java AWT

Previous Chapter 19
java.awt Reference
Next
 

Polygon

Name

Polygon

[Graphic: Figure from the text]

Description

The Polygon class encapsulates a collection of points used to create a series of line segments.

Class Definition

public class java.awt.Polygon
    extends java.lang.Object
    implements java.awt.Shape, java.io.Serializable {
  
  // Variables
  protected Rectangle bounds; (New)
  public int npoints;
  public int xpoints[];
  public int ypoints[];
  
  // Constructors
  public Polygon();
  public Polygon (int xpoints[], int ypoints, int npoints);
  
  // Instance Methods
  public void addPoint (int x, int y);
  public boolean contains (int x, int y); (New)
  public boolean contains (Point p); (New)
  public Rectangle getBoundingBox(); (Deprecated)
  public Rectangle getBounds(); (New)
  public boolean inside (int x,int y); (Deprecated)
  public void translate (int deltaX, int deltaY); (New)
}

Variables

bounds

protected Rectangle bounds (New)

The rectangle that describes the boundaries of the Polygon.

npoints

public int npoints

The number of elements to use in the xpoints and ypoints arrays.

xpoints

public int xpoints[]

The array of x coordinates for each point.

ypoints

public int ypoints[]

The array of y coordinates for each point.

Constructors

Polygon

public Polygon()

Description

Constructs an empty Polygon object with no points.

public Polygon (int xPoints[], int yPoints[], int numPoints)

Parameters

xPoints[]

The initial array of x coordinates for each point.

yPoints[]

The initial array of y coordinates for each point.

numPoints

The number of elements in both xPoints and yPoints arrays to use.

Throws

ArrayIndexOutOfBoundsException

If numPoints > xPoints.length or numPoints > yPoints.length.

Description

Constructs a Polygon object with the set of points provided.

Instance Methods

addPoint

public void addPoint (int x, int y)

Parameters

x

The x coordinate of the point to be added.

y

The y coordinate of the point to be added.

Description

Adds the point (x, y) to the end of the list of points for the Polygon.

contains

public boolean contains (int x, int y) (New)

Parameters

x

The x coordinate to test.

y

The y coordinate to test.

Returns

true if the Polygon contains the point; false otherwise.

public boolean contains (Point p) (New)

Parameters

p

The point to be tested.

Returns

true if the Polygon contains the point; false otherwise.

getBoundingBox

public Rectangle getBoundingBox() (Deprecated)

Returns

Bounding Rectangle of the points within the Polygon.

Description

Returns the smallest Rectangle that contains all the points within the Polygon. Replaced by getBounds().

getBounds

public Rectangle getBounds() (New)

Implements

Shape.getBounds()

Returns

Bounding Rectangle of the points within the Polygon.

Description

Returns the smallest Rectangle that contains all the points within the Polygon.

inside

public boolean inside (int x,int y) (Deprecated)

Parameters

x

The x coordinate of the point to be checked.

y

The y coordinate of the point to be checked.

Returns

true if (x, y) within Polygon, false otherwise.

Description

Checks to see if the (x, y) point is within an area that would be filled if the Polygon was drawn with Graphics.fillPolygon(). Replaced by contains(int, int).

translate

public void translate (int deltaX, int deltaY) (New)

Parameters

deltaX

Amount to move horizontally.

deltaY

Amount to move vertically.

Description

Moves the Polygon to the location (x+deltaX, y+deltaY).

See Also

Graphics, Object, Rectangle


Previous Home Next
Point Book Index PopupMenu (New)

Java in a Nutshell Java Language Reference Java AWT Java Fundamental Classes Exploring Java
This HTML Help has been published using the chm2web software.