/* Bill Marty's Java "Hello World" for iDEN phones. */ import javax.microedition.lcdui.*; import javax.microedition.midlet.*; interface Constants { public static final boolean DEBUG_ON = true; } public class Hello extends MIDlet { private Display myDisplay; //A reference to the physical display. private Form basicForm; //Stuff I want to show on the display. private Command exitCommand, moreCommand; private MyListener myCommands; public Hello(){ //Get the reference to my display object. myDisplay = Display.getDisplay(this); //Set up the soft keys. exitCommand = new Command("EXIT ", Command.EXIT, 2); moreCommand = new Command(" MORE", Command.SCREEN, 2); //Instantiate command listener. myCommands = new MyListener(); //Form is derived from Screen - the basic display mechanism. basicForm = new Form("Hello World"); basicForm.append("Hi Bill!\n"); basicForm.addCommand(moreCommand); basicForm.addCommand(exitCommand); basicForm.setCommandListener(myCommands); Debug.print("Hello constructed."); } private class MyListener implements CommandListener{ //React to soft key(s). public void commandAction(Command c, Displayable d) { if(c == exitCommand) { Debug.print("Exit Soft Key!"); //System.exit(0); destroyApp(false); notifyDestroyed(); } if(c == moreCommand) { basicForm.append("You want more!?\n"); Debug.print("MORE soft key pressed."); } } } // These are required to override abstract methods of MIDlet. public void startApp(){ //Show my Form. myDisplay.setCurrent(basicForm); } //No actions needed. public void pauseApp(){} public void destroyApp(boolean unconditional){} } class Debug implements Constants { static void print(String s){ if(Constants.DEBUG_ON == true) System.out.println(s); } }