Java Reference
In-Depth Information
Tour of MIDP Features
Now that you have run your first MIDlet, take a moment to admire it. There are several salient
features, even in such a small example.
It's Java
First of all,
Jargoneer
is written in the Java language, the same language you'd use to code servlets,
Enterprise JavaBeans, or J2SE client applications. If you're already a J2SE developer, you should
be quite comfortable developing MIDlets.
Not only is the Java language familiar, but also many core APIs are very similar to J2SE.
Notice, for example, that multithreading in
Jargoneer
is just the same as it might be in any
other Java code. The MIDlet class
Jargoneer
implements
java.lang
.
Runnable
, and the technique
for kicking off a new thread is the same as it always was:
Thread t = new Thread(this);
t.start();
Significant parts of
java.lang
are essentially unchanged from J2SE, as are parts of
java.io
and
java.util
. The code that reads the result from the server in
lookUp()
is familiar stream
handling, just like what you might see in J2SE.
MIDlet Life Cycle
Jargoneer
also demonstrates the basic structure of MIDlets. Like all MIDlets, it extends
javax.microedition.midlet.MIDlet
, the base class for all MIDP applications. Special software
on the device, called the Java Application Manager (JAM), Application Management Software
(AMS), or MIDlet management software, allows the user to control the process of installing,
running, and removing MIDlets. When a user chooses to run your MIDlet, it is the JAM that
creates an instance of the MIDlet class and runs methods on it.
The sequence of methods that will be called in your MIDlet subclass is defined by the MIDlet
life cycle. MIDlets, like applets and servlets, have a small set of well-defined states. The JAM will
call methods in the MIDlet to signify transitions from one state to another. You can see these
methods in
Jargoneer
—
startApp()
,
pauseApp()
,
destroyApp()
, and
Jargoneer
's constructor
are all part of the MIDlet life cycle.
Generalized User Interface
Jargoneer
's user-interface code may take you by surprise. Later on, we'll spend several chapters
on user interface. For now, the important thing to notice is how
Jargoneer
's user interface is
flexible enough to run on devices with different screen sizes and different input capabilities.
A big part of MIDP's appeal, after all, is the concept of writing one set of source code that runs
on multiple devices.
One example of MIDP's generalized user interface is the
TextBox
that is initially shown
when
Jargoneer
is launched. Figure 2-3 shows this
TextBox
.
Search WWH ::
Custom Search