TextBox: setCommandListener(CommandListener l) : TextBox « javax.microedition.lcdui « Java by API






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

1.new TextBox(String title, String text, int maxSize, int constraints)
2.TextBox: addCommand(Command cmd)
3.TextBox: setTicker(Ticker ticker)