TextBox: setCommandListener(CommandListener l)
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextBox;
import javax.microedition.midlet.MIDlet;
public class Main extends MIDlet implements CommandListener {
private Display display;
private TextBox textbox;
private Command exit = new Command("Exit", Command.SCREEN, 1);
public Main() {
display = Display.getDisplay(this);
String message = null;
if (display.isColor()) {
message = "Color display.";
} else {
message = "No color display";
}
textbox = new TextBox("Check Colors", message, 17, 0);
textbox.addCommand(exit);
textbox.setCommandListener(this);
}
public void startApp() {
display.setCurrent(textbox);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command command, Displayable displayable) {
if (command == exit) {
destroyApp(true);
notifyDestroyed();
}
}
}
Related examples in the same category