这一步很简单,增加一个NextCommand。
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
* @author netscaner
*/
public class Midlet extends MIDlet implements CommandListener {
private Form showForm;
private StringItem stringItem;
private Command exitCommand;
private Command NextCommand;
public StringItem getStringItem() {
if (stringItem == null) {
stringItem = new StringItem("Hello", "Hello, World!");
}
return stringItem;
}
public Form getForm() {
if (showForm == null) {
showForm = new Form("Welcome", new Item[] { getStringItem() });
showForm.addCommand(getExitCommand());
showForm.addCommand(getNextCommand());
showForm.setCommandListener(this);
}
return showForm;
}
public void startMIDlet() {
switchDisplayable(null, getForm());
}
public void exitMIDlet() {
switchDisplayable (null, null);
destroyApp(true);
notifyDestroyed();
}
public void switchDisplayable(Alert alert, Displayable nextDisplayable) {
Display display = getDisplay();
if (alert == null) {
display.setCurrent(nextDisplayable);
} else {
display.setCurrent(alert, nextDisplayable);
}
}
public Display getDisplay () {
return Display.getDisplay(this);
}
public Command getExitCommand() {
if (exitCommand == null) {
exitCommand = new Command("Exit", Command.EXIT, 0);
}
return exitCommand;
}
public Command getNextCommand() {
if (NextCommand == null) {
NextCommand = new Command("Next", Command.SCREEN, 0);
}
return NextCommand;
}
public void commandAction(Command command, Displayable displayable) {
if (displayable == showForm) {
if (command == exitCommand) {
exitMIDlet();
}
if (command == NextCommand) {
}
}
}
public void startApp() throws MIDletStateChangeException {
startMIDlet ();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}