paint() .Youcanworkwiththisinstanceasa Graphics instanceor(aftercasting
Graphics to Graphics2D ) as a Graphics2D instance.
The Graphics2D subclassinstancethat'spassedtoacomponent's paint() meth-
odidentifiesan output device (e.g.,monitororprinter)witha physical drawing surface
(e.g.,rasterscreenorprinterpage).Thissurfaceisassociatedwith device space ,which
isa2DCartesianplanewhosepixelsareknownas physical pixels ,andwhichhavein-
the GraphicsConfiguration thatwaspassedtothe Frame , JFrame , Window ,
or JWindow constructor that contains the component.
Atsomepoint, Graphics2D mustmaplogicalpixelstophysicalpixels.Itaccom-
plishesthistaskviaan affine transformation (amathematicaltransformationthattrans-
forms straight lines into straight lines and parallel lines into parallel lines).
By default, Java 2D specifies an affine transformation that aligns user space with
device space so that you end up with the coordinate system shown in Figure 7-7 . Fur-
Just keep in mind the default 72 user space coordinates to one inch mapping and Java
Graphics2D isalsoa rendering pipeline thatrenders(processes)shapes,text,andim-
that consists of the following attributes:
• Paint : A solid color, gradient (transition between two solid colors), or texture
(replicated image) applied to shape interiors and to a shape's outline shape.
• Stroke : An object that creates a shape to specify another shape's outline. The
resulting outline shape ,whichisalsoknownasa stroked outline ,isfilledwith
the paint attribute. Outline shapes don't have outlines.
• Font :Java2Drenderstextbycreatingshapesthatrepresentthetext'scharacters.
shapes are then filled.