Java Reference
In-Depth Information
You can use
null
for the
StringItem
's label or value to indicate that it should not be shown
on the screen. (Better yet, you could just use
Form
's
append(String)
method.)
StringItem
inherits
setLabel()
and
getLabel()
methods from
Item
. It also includes
getText()
and
setText()
methods for accessing and adjusting the string value.
The appearance of both
StringItem
and
ImageItem
can be controlled using
appearance
mode
. The appearance mode allows the item to look like a URL link or a button, although in
all other respects the item behaves the same as a regular
StringItem
or
ImageItem
. The three
appearance modes (which are defined in the
Item
class) are as follows:
•
PLAIN
shows the item in its normal state.
•
HYPERLINK
shows the item as a URL. A typical action would be to attempt to open the link
using
MIDlet
's
platformRequest()
method.
•
BUTTON
shows the item as a button. Note that this may be clumsy, especially on devices
without pointer events, and you should generally use a
Command
where you feel tempted
to use an item with a
BUTTON
appearance mode.
As with almost everything else in the
javax.microedition.lcdui
package, it's the imple-
mentation's responsibility to show different appearance modes, and your application may
look different on different devices. Furthermore, it is your application's responsibility to
implement appropriate behavior. For example, you might want to add a command to a
HYPERLINK StringItem
that calls
MIDlet
's
platformRequest()
method to open the link.
■
Note
The J2ME Wireless Toolkit emulators don't show
HYPERLINK
or
BUTTON StringItem
s any differently
from
PLAIN
ones, except for one special case. If the
StringItem
has a
BUTTON
type and it has an associated
item command, it is shown with a beveled border.
Finally, there are also
getFont()
and
setFont()
methods in the
StringItem
class. We'll
describe the
Font
class in Chapter 13.
Spacer
Spacer
represents empty space in a
Form
. Unlike other
Item
s,
Spacer
cannot gain focus and
cannot have commands. It may be used for layout purposes. All you need to do is specify a
minimum width and height:
public Spacer(minWidth, minHeight)
TextField
TextField
represents an editable string. Figure 6-7 shows a
TextField
with a label of
“TextFieldTitle” and a value of “text”.
In Sun's MIDP emulator, text can be entered directly into a
TextField
either by clicking the
number buttons in the emulator or by typing on the keyboard. Of course, it's up to the imple-
mentation to decide exactly how to allow editing. Some implementations may even show a
separate screen for editing.
Search WWH ::
Custom Search