Home J2me J2ME Command Class



J2ME Command Class
Posted on: November 20, 2008 at 12:00 AM
In the given J2ME Command Class example, we have set the various commands namely, screen, back, cancel, ok, help, stop, exit and item to the Midlet.

J2ME Command Class

     

In the given J2ME Command Class example, we have set the various commands namely, screen, back, cancel, ok, help, stop, exit and item to the Midlet. And also set the priority for it such as 1, 2, 3 etc. In J2ME commands are used for keeping information of the commands, not the action. For defining actions, CommandListener class are used. In this example we are going to show different commands on the screen but we have not used CommandListner class into it, that's these commands will not perform any action.

 

 

 

 

 

Our command class Midlet will look like as follow..

J2ME Command Class

Source Code of CommandMIDlet.java

import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;

public class CommandMIDlet extends MIDlet{
  private Form form;
  private Display display;
  private Command screen, back, cancel, ok, help, stop, exit, item;  
  
  public CommandMIDlet(){
  screen = new Command("Screen", Command.SCREEN, 1);
  back = new Command("Back", Command.BACK, 2);
  cancel = new Command("Cancel", Command.CANCEL, 3);
  ok = new Command("Ok", Command.OK, 4);
  help = new Command("Help", Command.HELP, 5);
  stop = new Command("Stop", Command.STOP, 6);
  exit = new Command("Exit", Command.EXIT, 7);
  item = new Command("Item", Command.ITEM, 8);
  }

  public void startApp(){
  display = Display.getDisplay(this);
  Form form = new Form("Command Priority");
  form.addCommand(screen);
  form.addCommand(back);
  form.addCommand(cancel);
  form.addCommand(ok);
  form.addCommand(help);
  form.addCommand(stop);
  form.addCommand(exit);
  form.addCommand(item);
  display.setCurrent(form);
  }

  public void pauseApp(){}

  public void destroyApp(boolean destroy){
  notifyDestroyed();
  }
}

 

Download Source Code

Related Tags for J2ME Command Class:
ccomclassj2meiohelpscreencommandnameidsetcommandsexitexampletostopidlmidletexamidletopeitbackitemcancelcommacanmidlvarmanceinasmcaletjclemmelmeackxaxampseekhaivmplandarvavariousxiscrssrithavstexipleplmindomo


More Tutorials from this section

Ask Questions?    Discuss: J2ME Command Class   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.