The High-Level User Interface API
A MIDlet written using the high-level API
typically consists of one or more screens built using the
Form, List, or
TextBox classes, together with a set of
Commands that allow the user to tell the MIDlet
what actions to perform and how to navigate from screen to screen.
Let’s start our examination of the high-level API by
creating a simple MIDlet with a single screen containing a
TextBox.
A TextBox Example
TextBox
is a component used to display and modify text. Since it is derived
from Screen, TextBox occupies
the entire screen of the device and therefore can accomodate
relatively large amounts of text spread over several lines. Most of
the API provided by TextBox is identical to that
of a similar component called TextField, which is
covered in detail in Section 4.2.9,
later in this chapter. In this example, we use only the features that
TextBox inherits from Screen
(and which are not available to TextField, because
it is not derived from Screen). The code for this
example is shown in Example 4-1.
Example 4-1. Creating and Using a TextBox
package ora.ch4; import java.io.InputStream; import java.io.InputStreamReader; import java.io.IOException; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.TextBox; import javax.microedition.lcdui.TextField; import javax.microedition.lcdui.Ticker; import javax.microedition.midlet.MIDlet; public class TextBoxMIDlet extends MIDlet { // Maximum size of the text in the TextBox private static ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access