3.1. Points

The java.awt.geom.Point2D class encapsulates a single point (an x and a y) in User Space. It is the most basic of the Java 2D classes and is used throughout the API. Note that a point is not the same as a pixel. A pixel is a tiny square (ideally) on a screen or printer that contains some color. A point, by contrast, has no area, so it can't be rendered. Points are used to build rectangles or other shapes that have area and can be rendered.

Point2D demonstrates an inheritance pattern that is used throughout java.awt.geom. In particular, Point2D is an abstract class with inner child classes that provide concrete implementations. Figure 3.1 shows Point2D's family tree. It's a pattern that you'll see again and again in the java.awt.geom package.

Figure 3.1. Point2D family of classes

Point2D represents a point in User Space, but it doesn't specify how the point's coordinates are stored. The subclasses provide different levels of precision for storing the coordinates of the point. The original java.awt.Point, which dates back to JDK 1.0, stores the coordinates as integers. Java 2D provides Point2D.Float and Point2D.Double for higher precision.

Sidebar 1. Find Your Inner Child

What's an inner child class?

An inner class , introduced to the Java language in JDK 1.1, is a class that is defined inside another class. For example, a class called Painter might have an inner ...

Get Java 2D Graphics now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.