A 2D virtual graphics device (VGD) consists of a canvas, a pen (for drawing lines on the canvas), a brush (for filling in shapes drawn on the canvas), a font (for writing text on the canvas), and a current color (the color of paint used for drawing, filling, and writing.) Of course the color can easily be changed. In addition, our VGD is equipped with methods for drawing polygons, ellipses, lines, curves, and custom shapes.
With the help of the operating system operations performed by the VGD are translated into operations performed by the computer's graphics card. Java programmers don't need to worry about this translation. A Java graphics program only needs to know about the VGD and is therefore platform independent.
The VGD's canvas is equipped with a coordinate system with origin in the upper left corner:
The canvas is visible through a resizable window that has the origin as its upper left corner:
Actually, Java has two coordinate systems: device space and user space.
Device space coordinates are integers and the units are pixels.
Study the APIs for the following java.awt classes:
java.awt.Point
java.awt.Rectangle
User space coordinates are floats or doubles.
A point represents a point in a real plane.
Java automatically maps user space coordinates onto device space coordinates.
See the APIs for the following java.awt.geom classes:
java.awt.geom.Point2D.Double
java.awt.geom.Rectangle2D.Double
java.awt.geom.Ellipse2D.Double