Java Reference
In-Depth Information
The Graphics class contains the usual gamut of interfaces for drawing to the Canvas
that you might expect, including methods to draw strings, lines, arcs, individual pixels,
and images. Its interface is similar to, but not the same as, the Java SE Graphics class, so
it's best to check the MIDP documentation before writing code that uses this class.
Creating a Custom Item for a Screen
The CustomItem class gives you an abstract class from which to implement a new interac-
tive Item that you can place on a Form . CustomItem instances must be able to do the
following:
• Determine their appropriate size
• Draw the contents of the item
• Respond to events generated by keys, pointers, and traversal of its internal focus-
able subitems (entry and exit of each focusable subitem)
• Invoke the notifyStateChanged method when the value has changed
Item objects, including CustomItem subclasses, interact with their parent object via the
notion of a minimum and preferred size. The former size is the smallest size the parent
may give the CustomItem , while the latter is the size the CustomItem would like to occupy on
the parent. For a given CustomItem , the content size describes the actual region the parent
has allocated for its drawing; a CustomItem must draw its contents in that area. To make
matters simpler, the parent communicates the content region in coordinates relative to
the CustomItem —that is, the upper-left corner of the CustomItem is (0,0) . Sizing from your
CustomItem to the parent is passed via the following methods:
getMinContentHeight and getMinContentWidth : Let you specify your CustomItem 's
minimum height and width, respectively
getPrefContentHeight and getPrefContentWidth : Let you specify the preferred height
and width for your CustomItem (possibly based on its current contents)
The parent form passes your CustomItem 's actual bounds—the content bounds—to
your paint method. Like a Canvas , you override paint to provide the code that repaints the
CustomItem 's region. You must paint every pixel clipped by the provided Graphics instance.
Unlike the Canvas , whose bounds are set by methods, your content bounds are passed as
arguments to the paint method. You can also schedule redraws using the repaint method,
just as you might a Canvas .
The events a CustomItem may receive depend on the MIDP implementation, which is
a barrier to application portability. Your implementation may determine which events it
supports by invoking CustomItem.getInteractionModes ; the resulting integer is a bit mask
 
Search WWH ::




Custom Search