Name
Graphics
Synopsis
The Graphics
class provides drawing and fill operations
that can be used to paint the content of a Canvas
or
a mutable Image
. A Graphics
object for
a Canvas
is passed to its
paint()
method and is
valid only within that method. A Graphics
object for an
Image
can be obtained from its getGraphics()
method and remains valid as long as the Image
is referenced.
All operations on a Graphics
object use a coordinate reference
system measured in pixels, in which the origin is initially at the top-left hand
corner of the Canvas
or Image
. Values of the
x
coordinate increase when moving to the right, while y
value increase downwards. The coordinate origin may be moved by calling the
translate()
method, supplying the coordinates of the new origin
relative to the current origin. Negative coordinate values are valid and, depending on
the location of the origin, may or may not correspond to points on the drawing surface.
It is permissible to move the origin to a location that is outside the drawing area.
A Graphics
object has an associated clipping rectangle
which bounds the area within which graphics operations will be performed. The clipping rectangle
for an Image
is initially set to cover the entire image, while that for
a Canvas
is set by the platform to cover the part of the Canvas
that needs to be repainted. Operations performed on a Graphics
object will not change pixels that lie outside clipping rectangle, even if their scope would include those pixels. Thus, setting ...
Get J2ME in a Nutshell 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.