Drawing directly on a screen

Every class that extends the Field class has a paint() method. The paint() method determines how a field draws its contents. For classes that are included in the BlackBerry® Java® SDK, paint() is implemented in the class itself. For example, prebuilt UI components such as buttons and drop-down lists have paint() methods that describe how to draw the contents of the component, such as the text of the button or the items in the drop-down list. For classes that you create for custom UI components, you implement paint() to specify how to draw the component.

To draw on the screen of a BlackBerry device directly, you must override paint() of the Screen object that you want to draw on. The paint() method receives a Graphics object as a parameter, which represents the surface of a field that your application can draw on. You can then use the methods of the Graphics class, which is included in the net.rim.device.api.ui package, to draw content on the screen, such as shapes, text, and graphics. The Graphics object that paint() receives contains state information that is required for rendering operations, such as the current font and drawing color.

Next topic: Context stack

Was this information helpful? Send us your comments.