|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.microedition.lcdui.Displayable | +--javax.microedition.lcdui.Screen | +--javax.microedition.lcdui.Form
A Form is a Screen
that contains an arbitrary mixture of
items: Images
, non-editable StringItems
,
editable TextFields
, editable
DateFields
, Gauges
,
and ChoiceGroups
. In general, any subclass of the
Item
class may be contained within a Form. The
implementation handles layout, traversal, and scrolling. None of the
components contained within has any internal scrolling; the entire
contents scrolls together. Note that this differs from the behavior
of other classes, the List
for example, where only the interior
scrolls.
The Items contained within a Form may be edited using
append()
, delete()
,
insert()
, and set()
methods. Items within a Form are referred to by their
indexes, which are consecutive integers in the range from zero to size() - 1,
with zero referring to the first item and size()-1 to the last item.
An item may be placed within at most one Form. If the application attempts to place an item into a Form, and the item is already owned by this or another Form, an IllegalStateException is thrown. The application must remove the item from its currently containing Form before inserting it to the new Form.
As with other screens, the layout policy in most devices is vertical. In Forms this applies to items involving user input. So, a new line is always started for focusable items like TextField, DateField, Gauge or ChoiceGroup.
Strings and images, which do not involve user interactions, behave
differently; they are filled in horizontal lines, unless newline is embedded
in the string or layout directives of the ImageItem
force a new line. Contents will be wrapped (for text) or clipped (for
images) to fit the width of the display, and scrolling will occur
vertically as necessary. There will be no horizontal scrolling.
If the Form is visible on the display when changes to its contents are requested by the application, the changes take place immediately. That is, applications need not take any special action to refresh a Form's display after its contents have been modified.
When a Form is present on the display the user can interact with it and its
Items indefinitely (for instance, traversing from Item to Item and possibly
scrolling). These traversing and scrolling operations do not cause
application-visible events. The system notifies the application when the
user modifies the state of an interactive Item contained within the Form.
This notification is accomplished by calling the
itemStateChanged(Item)
method of the listener declared to the Form with the
setItemStateListener(ItemStateListener)
method.
As with other Displayable object, a Form can declare a
Command
and declare a command listener with the
setCommandListener(CommandListener)
method.
CommandListener
objects are distinct from the
ItemStateListener
object, and they are declared and
invoked separately.
Notes for application developers:
Constructor Summary | |
Form(String title)
Creates a new, empty Form. |
|
Form(String title,
Item[] items)
Creates a new Form with the specified contents. |
Method Summary | |
int |
append(Image img)
Adds an item consisting of one Image to the Form. |
int |
append(Item item)
Adds an Item into the Form. |
int |
append(String str)
Adds an item consisting of one String to the Form. |
void |
delete(int itemNum)
Deletes the Item referenced by itemNum. |
Item |
get(int itemNum)
Gets the item at the given position. |
void |
insert(int itemNum,
Item item)
Inserts an item into the Form just prior to the item specified. |
void |
set(int itemNum,
Item item)
Sets the item referenced by itemNum to the specified item, replacing the previous item. |
void |
setItemStateListener(ItemStateListener iListener)
Sets the ItemStateListener for the Form, replacing any previous ItemStateListener. |
int |
size()
Gets the number of items in the Form. |
Methods inherited from class javax.microedition.lcdui.Screen |
getTicker,
getTitle,
setTicker,
setTitle |
Methods inherited from class javax.microedition.lcdui.Displayable |
addCommand,
isShown,
removeCommand,
setCommandListener |
Methods inherited from class java.lang.Object |
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Constructor Detail |
public Form(String title)
title
- the Form's title, or null for no titlepublic Form(String title, Item[] items)
title
- the Form's title stringitems
- the array of Items
to be placed in the Form, or
null if there are no Items.Method Detail |
public int append(Image img)
append(new ImageItem(null, img,
ImageItem.LAYOUT_DEFAULT, null))
img
- the image to be addedImageItem
public int append(Item item)
Images are laid out in the same manner as strings, unless the layout
directives of ImageItem
specify otherwise. Focusable
items (TextField
, ChoiceGroup
,
DateField
, and Gauge
) are placed on their
own horizontal lines.
item
- the Item
to be added.public int append(String str)
append(new StringItem(null, str))
str
- the String to be addedpublic void delete(int itemNum)
itemNum
- the index of the item to be deletedpublic Item get(int itemNum)
itemNum
- index of the item to be retrievedpublic void insert(int itemNum, Item item)
The semantics are otherwise identical to
append(Item)
.
itemNum
- index where insertion is to occuritem
- the item to be insertedpublic void set(int itemNum, Item item)
The end result is equal to
insert(n, item);
delete(n+1);
itemNum
- index of the item to be replaced.item
- the new item to be placed in the Formpublic void setItemStateListener(ItemStateListener iListener)
iListener
- the new listener, or null to remove itpublic int size()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |