Java Reference
In-Depth Information
positioning components in containers. The origin is at the top-left corner of the component; the positive x -
axis runs from left to right, and the positive y -axis from top to bottom. Coordinates are usually specified as
floating-point values, although you can also use integers.
A particular graphical output device has its own device coordinate system, or device space, as illustrated
in Figure 19-4 . This coordinate system has the same orientation as the default user coordinate system, but
the coordinate units depend on the characteristics of the device. Your display, for example, has a different
device coordinate system for each configuration of the screen resolution, so the coordinate system when
your display is set to a resolution 1024 × 768 pixels is different from the coordinate system for 1920× 1080
pixels.
FIGURE 19-4
NOTE Incidentally, the drawing process is often referred to as rendering. Graphical output
devicesaregenerallyrasterdevicesthatdisplayanimageasarectangulararrayofpixelsand
drawing elements such as lines, rectangles, text, and so on need to be rendered into a raster-
ized representation before they can be output to the device.
Having a device-independent coordinate system for drawing means that you can use essentially the same
code for writing graphical information to a variety of different devices — to your display screen, for ex-
ample, or to your printer — even though these devices themselves have quite different coordinate systems
with different resolutions. The fact that your screen might have 90 pixels per inch and your printer may have
600 dots per inch is automatically taken care of. Java 2D deals with converting your user coordinates to the
device coordinate system that is specific to the output device you are using.
Graphics Contexts
The user coordinate system for drawing on a component using Java 2D is encapsulated in an object of type
java.awt.Graphics2D , which is usually referred to as a graphics context . It provides all the tools you need
to draw whatever you want on the surface of the component. A graphics context enables you to draw lines,
 
 
Search WWH ::




Custom Search