Java Reference
In-Depth Information
L
ISTING
5.3
Continued
mainList = null;
}
/**
* To launch the MIDlet
*/
protected void startApp() throws MIDletStateChangeException {
mainList = new List(“Select a Number”,
List.IMPLICIT,
new String[] {“Option 1”,”Option 2”,”Option 3”,
➥
”Register”},
null);
Display.getDisplay(this).setCurrent(mainList);
mainList.setCommandListener(this);
}
/**
* handles user commands
*/
public void commandAction(Command c, Displayable d) {
int pos = mainList.getSelectedIndex();
if (pos==3){
licenseManager.register();
}
try {
show(“Hello!”, “OK?”);
}
catch(Exception err) {
show(“Error”, “general exception”);
}
}
/**
* utility method to show modal alerts
*/
private void show(String title, String txt){
Alert a = new Alert(title);
a.setString(txt);
a.setTimeout(Alert.FOREVER);
Display.getDisplay(this).setCurrent(a);
5
}
}