Get command label and type : Command « J2ME « Java Tutorial

Get command label and type
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.TextBox;
import javax.microedition.midlet.MIDlet;

public class J2MECommandGetter extends MIDlet implements CommandListener {

  private Command exitCommand = new Command("EXIT", Command.EXIT, 1);

  private Command infoCommand = new Command("info", Command.SCREEN, 1);

  TextBox t= new TextBox("Hello MIDP", "Welcome to MIDP Programming", 256, 0);

  private Display display;

  public J2MECommandGetter() {
    display = Display.getDisplay(this);

  public void startApp() {

  public void pauseApp() {

  public void destroyApp(boolean unconditional) {

  public void commandAction(Command c, Displayable s) {
    if (c == exitCommand) {
    if (c == infoCommand) {
      ((TextBox) s).setString(infoCommand.getLabel() + " " + infoCommand.getCommandType()
          + infoCommand.getPriority());

31.17.1.Add Command to MIDlet
31.17.2.Start the MIDlet by creating a list of items and associating the exit command with itStart the MIDlet by creating a list of items and associating the exit command with it
31.17.3.A MIDlet with simple text and a few commands.
31.17.4.Get command label and typeGet command label and type
31.17.5.Exit Command
31.17.6.Help commandHelp command