Graphics Attributes

The Graphics class provides operations that let you do the following:

  • Draw straight lines, arcs, and rectangles

  • Fill the space occupied by an arc or a rectangle

  • Render images

  • Draw text presented in the form of a String or as character data

All these operations use a coordinate system to indicate at least their starting point, and most of them also use one or more attributes of the Graphics object that act as implicit parameters. When the paint( ) method is called, the attributes of the Graphics object that is passed to it have well-defined values that can be modified if necessary. The attributes and their initial values are listed in Table 5-1. A more detailed description of each attribute and the way in which it is used are found in later sections.

Table 5-1. Graphics Attributes

Attribute

Use

Initial Value

Clip

The clip sets the region of the Canvas within which graphics operations have any effect. The clip is discussed in Section 5.7.

Depends on the reason paint( ) was invoked

Color

The color that will be used when drawing or filling shapes or rendering text. See Section 5.3.2 for further details.

Black

Font

The font used when rendering text. Fonts are discussed in Section 5.8.

Set to the platform’s default font

Stroke Style

Determines whether lines, rectangles, and arcs are drawn using solid or dotted strokes, as described in Section 5.4.1.

Set to draw a solid line

Origin

The position of the coordinate point (0, 0) relative to the top left ...

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.