#

| Chapter 19 java.awt Reference |

# Point

## Name

Point

##

## 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();
      public Point (int width, int height);
      public Point (Point p);

      // Instance Methods
      public boolean equals (Object object);
      public Point getLocation();
      public int hashCode();
      public void move (int x, int y);
      public void setLocation (int x, int y);
      public void setLocation (Point p);
      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()

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)

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()

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)

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)

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`

Panel |  | Polygon