Creating MIDlets
Now that you’re familiar with MIDlet states and the application manager, let’s create another MIDlet. As you’ve probably guessed by now, this involves the following five steps:
Write the MIDlet.
Compile the MIDlet’s source code.
Preverify the MIDlet’s class file.
Package the application in a JAR file.
Create a JAD file.
Let’s review each of these steps. First, we’ll look at the command-line technique that was shown in Chapter 1. Then, we’ll introduce the KToolbar application, which comes with the J2ME Wireless Toolkit and which can make our lives much easier.
Write the MIDlet
The
first
step in the development life cycle is to write the MIDlet. Example 4-2 shows a simple MIDlet,
PaymentMIDlet. This MIDlet creates a
List object of type EXCLUSIVE (that is, only one option
can be selected at a time), and adds three methods of payments to it.
It displays a list of options for the user to select a method of
payment.
Example 4-2. Sample MIDlet
import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class PaymentMIDlet extends MIDlet { // The display for this MIDlet private Display display; // List to display payment methods List method = null; public PaymentMIDlet( ) { method = new List("Method of Payment", Choice.EXCLUSIVE); } public void startApp( ) { display = Display.getDisplay(this); method.append("Visa", null); method.append("MasterCard", null); method.append("Amex", null); display.setCurrent(method); } /** * Pause is a no-op since there are no background ...