Java Reference
In-Depth Information
CHAPTER 4
Introducing MIDlets
T he MIDlet is at the heart of the Java ME CLDC execution model. MIDlets are the
equivalent of applications in the CLDC/MIDP domain, processing input from the user
and presenting output. MIDlets also manage interactions with the system, responding
to requests for resources by pausing and yielding control of the system to the interrupt-
ing application.
In this chapter, I discuss the MIDlet interface that you must implement within
your application. I begin by showing you the source code for the simplest MIDlet, and
I discuss the methods you must implement to satisfy the MIDlet interface. I discuss the
life cycle of MIDlets, and I give you more information on packaging MIDlets. Next, I
show you how a MIDlet loads properties and resources from its accompanying JAR file.
Finally, I show you the various ways you can start MIDlets.
Looking at the Simplest MIDlet
Listing 4-1 shows a simple Hello World MIDlet, which implements the methods required
of all MIDlets. This MIDlet presents a single (editable) text box with the message “Hello
World.”
Listing 4-1. The Hello World MIDlet
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class HelloMidlet extends MIDlet {
public HelloMidlet() {
}
public void startApp() {
Display.getDisplay(this).setCurrent(
new TextBox("", "Hello World", 20, 0) );
}
83
 
Search WWH ::




Custom Search