Java Reference
In-Depth Information
Listing 6-1. The TravelList Source Code
import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class TravelList
extends MIDlet
implements CommandListener {
private List mList;
private Command mExitCommand, mNextCommand;
public TravelList() {
String[] stringElements = { "Airplane", "Car", "Hotel" };
Image[] imageElements = { loadImage("/airplane.png"),
loadImage("/car.png"), loadImage("/hotel.png") };
mList = new List("Reservation type", List.IMPLICIT,
stringElements, imageElements);
mNextCommand = new Command("Next", Command.SCREEN, 0);
mExitCommand = new Command("Exit", Command.EXIT, 0);
mList.addCommand(mNextCommand);
mList.addCommand(mExitCommand);
mList.setCommandListener(this);
}
public void startApp() {
Display.getDisplay(this).setCurrent(mList);
}
public void commandAction(Command c, Displayable s) {
if (c == mNextCommand || c == List.SELECT_COMMAND) {
int index = mList.getSelectedIndex();
Alert alert = new Alert("Your selection",
"You chose " + mList.getString(index) + ".",
null, AlertType.INFO);
Display.getDisplay(this).setCurrent(alert, mList);
}
else if (c == mExitCommand)
notifyDestroyed();
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
Search WWH ::




Custom Search