Java Reference
In-Depth Information
Tab
l
e 3.2.
ImageItem
Layout Constants
Constant
Value
LAYOUT_CENTER
The image is centered horizontally.
LAYOUT_DEFAULT
A device-dependent default formatting is applied to the image.
LAYOUT_LEFT
The image is left-aligned.
LAYOUT_NEWLINE_AFTER
A new line will be started after the image is drawn.
LAYOUT_NEWLINE_BEFORE
A new line will be started before the image is drawn.
LAYOUT_RIGHT
The image is aligned to the right.
The following code snippet shows how a center aligned
ImageItem
is added to the
HelloMidp
sample MIDlet:
public HelloMidp() {
display = Display.getDisplay (this);
mainForm = new Form ("HelloMidp");
try {
ImageItem logo = new ImageItem
("Copyright: ", Image.createImage ("/mcp.png"),
ImageItem.LAYOUT_CENTER | mageItem.LAYOUT_NEWLINE_BEFORE
| ImageItem.LAYOUT_NEWLINE_AFTER, "Macmillian USA");
mainForm.append (logo);
} catch (IOException e) {
mainForm.append (new StringItem ("Copyright", "Sams
Publishing; Image not available:" + e));
}
}
By forcing a new line before and after the image, you ensure that the image is centered in its own line.
Figure 3.3
shows the corresponding display on the device. If the image cannot be loaded and an
exception is thrown, a simple
StringItem
is appended to the form instead of the image.
Figure 3.3. The
HelloMidp
application showing an
ImageItem
.
Handling Textual Input in
TextField
s
TextField
takes four values: a label, initial text, a maximum text size, and constraints that indicate
the type of input allowed. In addition to avoiding input of illegal characters, the constraints may also
influence the keyboard mode. Several MIDP devices have a numeric keyboard only, and the constraints
allow the application manager to switch the key assignments accordingly. The constants listed in
Table
Table 3.3.
TextField Constraint
Constant Values
Constant
Value
Search WWH ::
Custom Search