// This project maps Command to a Button import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class CommandMap extends MIDlet implements CommandListener{ private Display myDisplay; // reference to display private Form Main; // define main form private TextBox tbHelp; // textbox for displaying text message private Command Exit; // command for exit private Command Help; // help command private Command Back; // return to the main form public CommandMap(){ myDisplay = Display.getDisplay(this); Back = new Command("Back", Command.BACK,1); Help = new Command("Help", Command.HELP,1); Exit = new Command("Exit", Command.EXIT,1); // create the form - add commands - listen for events //First screen commands Main = new Form ("J2ME Commands"); Main.addCommand(Exit); Main.addCommand(Help); Main.setCommandListener(this); // create help textbox with maximum 30 characters tbHelp = new TextBox("Help", "This text is here to Help you!", 30,0); tbHelp.addCommand(Back); // add the back command to the screen tbHelp.setCommandListener(this); } // start MIDlet public void startApp(){ myDisplay.setCurrent(Main); } public void pauseApp(){ } public void destroyApp(boolean unconditional){ } // process events public void commandAction(Command c, Displayable s){ if (c == Exit){ destroyApp(false); notifyDestroyed(); } else if (c ==Help) myDisplay.setCurrent(tbHelp); else if (c == Back) myDisplay.setCurrent(Main); } }