Skip to main content
Engineering LibreTexts

1.1: Point Objects

  • Page ID
  • The java.awt package provides a class named Point intended to represent the coordinates of a location in a Cartesian plane. In mathematical notation, points are often written in parentheses with a comma separating the coordinates. For example, (0,0) indicates the origin, and (x,y) indicates the point x units to the right and y units up from the origin.

    In order to use the Point class, you have to import it:

    import java.awt.Point;

    Then, to create a new point, you have to use the new operator:

    Point blank;
    blank = new Point(3, 4);

    The first line declares that blank has type Point. The second line creates the new Point with the given arguments as coordinates.

    The result of the new operator is a reference to the new object. So blank contains a reference to the new Point object. Figure 10.1.1 shows the result.

    State diagram showing a variable that refers to a Point object.
    Figure \(\PageIndex{1}\): State diagram showing a variable that refers to a Point object.

    As usual, the name of the variable blank appears outside the box, and its value appears inside the box. In this case, the value is a reference, which is represented with an arrow. The arrow points to the new object, which contains two variables, x and y.

    • Was this article helpful?