FileDocCategorySizeDatePackage
EventEx1.javaAPI DocExample3069Sat Jan 05 11:47:12 GMT 2002None

EventEx1

public class EventEx1 extends MIDlet implements CommandListener

Fields Summary
Display
display
List
menu
TextBox
input
static final Command
backCommand
static final Command
mainMenuCommand
static final Command
exitCommand
String
currentMenu
Constructors Summary
public EventEx1()


   // constructor.
     
   
Methods Summary
public voidcommandAction(Command c, Displayable d)
Handle events.

      String label = c.getLabel();
      if (label.equals("Exit")) {
         destroyApp(true);
      } else if (label.equals("Back")) {
         if(currentMenu.equals("item1") || currentMenu.equals("item2") ||
            currentMenu.equals("item3") || currentMenu.equals("item4"))  {
            // go back to menu
            mainMenu();
         } 

      } else {
         List down = (List)display.getCurrent();
         switch(down.getSelectedIndex()) {
            case 0: testItem1();break;
            case 1: testItem2();break;
            case 2: testItem3();break;
            case 3: testItem4();break;
         }
      }
   
public voiddestroyApp(boolean unconditional)

      notifyDestroyed();
   
voidmainMenu()

      display.setCurrent(menu);
      currentMenu = "Main"; 
   
public voidpauseApp()

      display = null;
      menu = null;
      input = null;
   
public voidprepare()
a generic method that will be called when selected any of the items on the list.

      input = new TextBox("Enter some text: ", "", 5, TextField.ANY);
      input.addCommand(backCommand);
      input.setCommandListener(this);
      input.setString("");
      display.setCurrent(input);
   
public voidstartApp()
Start the MIDlet by creating a list of items and associating the exit command with it.

      display = Display.getDisplay(this);
      menu = new List("Menu Items", Choice.IMPLICIT);
      menu.append("Item1", null);
      menu.append("Item2", null);
      menu.append("Item3", null);
      menu.append("Item4", null);
      menu.addCommand(exitCommand);
      menu.setCommandListener(this);

      mainMenu();
   
public voidtestItem1()
Test item1.

      prepare();
      currentMenu = "item1";
   
public voidtestItem2()
Test item2.

      prepare();
      currentMenu = "item2"; 
   
public voidtestItem3()
Test item3.

      prepare();
      currentMenu = "item3"; 
   
public voidtestItem4()
Test item4.

      prepare();
      currentMenu = "item4";