Java AWT

Previous Chapter 19
java.awt Reference
Next
 

Point

Name

Point

[Graphic: Figure from the text]

Description

The Point class encapsulates a pair of x and y coordinates within a single object.

Class Definition

public class java.awt.Point
    extends java.lang.Object
    implements java.io.Serializable {
  // Variables
  public int x;
  public int y;
  
  // Constructors
  public Point(); (New)
  public Point (int width, int height);
  public Point (Point p); (New)
  
  // Instance Methods
  public boolean equals (Object object);
  public Point getLocation(); (New)
  public int hashCode();
  public void move (int x, int y);
  public void setLocation (int x, int y); (New)
  public void setLocation (Point p); (New)
  public String toString();
  public void translate (int deltax, int deltay);
}

Variables

x

public int x

The coordinate that represents the horizontal position.

y

public int y

The coordinate that represents the vertical position.

Constructors

Point

public Point() (New)

Description

Constructs a Point object initialized to (0, 0).

public Point (int x, int y)

Parameters

x

Coordinate that represents the horizontal position.

y

Coordinate that represents the vertical position.

Description

Constructs a Point object with an initial position of (x, y).

public Point (Point p) (New)

Parameters

p

Initial position.

Description

Constructs a Point object with the same position as p.

Instance Methods

equals

public boolean equals (Object object)

Parameters

object

The object to compare.

Returns

true if both points have the same x and y coordinates, false otherwise.

Overrides

Object.equals()

Description

Compares two different Point instances for equivalence.

getLocation

public Point getLocation() (New)

Returns

Position of this point.

Description

Gets the current position of this Point.

hashCode

public int hashCode()

Returns

A hashcode to use the Point is used as a key in a Hashtable.

Overrides

Object.hashCode()

Description

Generates a hashcode for the Point.

move

public void move (int x, int y)

Parameters

x

The new x coordinate.

y

The new y coordinate.

Description

Changes the Point's location to (x, y).

setLocation

public void setLocation (int x, int y) (New)

Parameters

x

The new x coordinate.

y

The new y coordinate.

Description

Changes the Point's location to (x, y).

public void setLocation (Point p) (New)

Parameters

p

The new location.

Description

Changes the Point's location to p.

toString

public String toString()

Returns

A string representation of the Point object.

Overrides

Object.toString()

translate

public void translate (int deltax, int deltay)

Parameters

deltax

Amount to move horizontally.

deltay

Amount to move vertically.

Description

Moves the Point to the location (x+deltax, y+deltay).

See Also

Object, String


Previous Home Next
Panel Book Index Polygon

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