Skip to Main Content
Wireless Java
book

Wireless Java

by Qusay H. Mahmoud
January 2002
Intermediate to advanced content levelIntermediate to advanced
264 pages
8h 3m
English
O'Reilly Media, Inc.
Content preview from Wireless Java

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:

  1. Write the MIDlet.

  2. Compile the MIDlet’s source code.

  3. Preverify the MIDlet’s class file.

  4. Package the application in a JAR file.

  5. 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 ...
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.
Start your free trial

You might also like

Wireless J2ME™ Platform Programming

Wireless J2ME™ Platform Programming

Vartan Piroumian
Java Power Tools

Java Power Tools

John Ferguson Smart

Publisher Resources

ISBN: 0596002432Supplemental ContentCatalog PageErrata