Here’s a little program that takes me from a menu list to a form, and back.
But can you tell me why my Back-Button won’t work?
import javax.microedition.midlet.;
import javax.microedition.lcdui.;
import java.util.*;
public class Testing extends MIDlet implements CommandListener {
private Command exitCommand = new Command(“Exit”, Command.EXIT, 2);
private Command goCommand = new Command(“Go”, Command.OK, 2);
private Command backCommand = new Command(“Back”, Command.BACK, 2);
private Display display;
private Alert resultAlert;
private List list;
public static final String[] items = {“Choice 1”, “Choice 2”, “Choice 3”, “Choice 4”};
public Testing() {
display = Display.getDisplay(this);
list = new List("", List.IMPLICIT, items, null);
list.addCommand(exitCommand);
list.addCommand(goCommand);
list.setCommandListener(this);
}
public void startApp() throws MIDletStateChangeException {
display.setCurrent(list);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
int len, i;
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
} else if (c == goCommand) {
Form resultSet = new Form(“Results of Your Search”);
String[] strings = {“Here is a page”, “written by a sage”};
len = strings.length;
for (i=0; i<len; i++ ) {
resultSet.append(strings[i] + “\n”);
}
resultSet.addCommand(backCommand);
display.setCurrent(resultSet);
}
}
}