Java Reference
In-Depth Information
As a subclass of Screen and Displayable , Form inherits both a title and a ticker. Given the
small screen size of a typical MIDP device, however, you may want to avoid using a ticker with
your forms.
Caution The use of a ticker may also affect battery life on a small device, due to the need to constantly
update the ticker's display area.
Form 's grandparent class, Displayable , gives Form the capabilities of displaying commands
and firing command events. Again, you should probably keep commands simple with forms; in
many cases a Next and a Back will probably be sufficient.
As with any Displayable , the basic strategy for showing a Form is to create one and pass it
to Display 's setCurrent() method. If you have a form that is larger than the Display , you may
want to use the setCurrentItem() method in Display . This method makes the form containing
the item visible, then it scrolls the form so the item is visible and has input focus.
Managing Items
Items may be added and removed, even while the Form is showing. The order of items is important
as well; most MIDP implementations will display a form's items top to bottom and possibly left
to right, scrolling the form vertically as needed if there are more items than available screen space.
To add an Item to the bottom of a form, use one of the append() methods. The first one can
be used to add any Item implementation. The second two append() methods are strictly for
convenience; behind the scenes, a StringItem or an ImageItem will be created for you.
public int append(Item item)
public int append(String str)
public int append(Image image)
Every item in a form has an index. You can place an item at a specific index (replacing the
previous item at that index) using the method:
public void set(int index, Item item)
Alternately, if you'd like to add an item somewhere in the middle of the form, just supply
the desired index for the new item to the insert() method. Subsequent items will move up by
one index.
public void insert(int index, Item item)
To remove an item from a form, use delete() .
public void delete(int index)
To remove all items with one call, use deleteAll() .
public void deleteAll()
 
Search WWH ::




Custom Search