org.j4me.ui
Class Menu

java.lang.Object
  extended by org.j4me.ui.DeviceScreen
      extended by org.j4me.ui.Dialog
          extended by org.j4me.ui.Menu

public class Menu
extends Dialog

The Menu class is used for creating the application's menus.

J2ME devices have small screens and are not all very responsive to scrolling. However, they do have keypads. The Menu class respects this and limits menus to a total of 9 possible choices (1-9) plus "Exit". Usually all the choices can be seen on a single screen and selected with a single button.

Override this class to change how the menu is painted for your application.


Field Summary
protected  DeviceScreen previous
          The screen that invoked this one or null if there is no previous screen.
 
Fields inherited from class org.j4me.ui.DeviceScreen
DOWN, FIRE, GAME_A, GAME_B, GAME_C, GAME_D, KEY_NUM0, KEY_NUM1, KEY_NUM2, KEY_NUM3, KEY_NUM4, KEY_NUM5, KEY_NUM6, KEY_NUM7, KEY_NUM8, KEY_NUM9, KEY_POUND, KEY_STAR, LEFT, MENU_LEFT, MENU_RIGHT, RIGHT, UP
 
Constructor Summary
Menu()
          Constructs a menu.
Menu(java.lang.String name, DeviceScreen previous)
          Constructs a menu.
 
Method Summary
protected  void acceptNotify()
          The right menu button selects the highlighted menu item.
 void appendMenuOption(DeviceScreen option)
          Appends a screen as a menu option.
 void appendMenuOption(MenuItem option)
          Appends a new menu option to this menu.
 void appendMenuOption(java.lang.String text, DeviceScreen option)
          Appends a screen as a menu option.
 void appendSubmenu(Menu submenu)
          Appends another menu as a menu option.
protected  void declineNotify()
          The left menu button takes the user back to the previous screen.
protected  void keyPressed(int key)
          Responds to key press events that are specific to menu screens.
 void setPrevious(DeviceScreen previous)
          Sets the screen to return to if the user cancels this menu.
 
Methods inherited from class org.j4me.ui.Dialog
append, components, delete, delete, deleteAll, get, getMargin, getSelected, getSpacing, getWidth, hasVerticalScrollbar, hideNotify, insert, invalidate, keyReleased, keyRepeated, paint, paintVerticalScrollbar, pointerDragged, pointerPressed, pointerReleased, set, setFullScreenMode, setMargin, setMenuText, setSelected, setSelected, setSpacing, setTitle, size
 
Methods inherited from class org.j4me.ui.DeviceScreen
getCanvas, getHeight, getLeftMenuText, getRightMenuText, getScreenHeight, getScreenWidth, getTitle, hasMenuBar, hasTitleBar, intersects, isFullScreenMode, isShown, paintBackground, paintMenuBar, paintTitleBar, repaint, repaint, serviceRepaints, show, showNotify, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

previous

protected DeviceScreen previous
The screen that invoked this one or null if there is no previous screen.

Constructor Detail

Menu

public Menu()
Constructs a menu.


Menu

public Menu(java.lang.String name,
            DeviceScreen previous)
Constructs a menu.

Parameters:
name - is the title for this menu, for example "Main Menu". It appears at the top of the screen in the title area.
previous - is the screen to return to if the user cancels this.
Method Detail

setPrevious

public void setPrevious(DeviceScreen previous)
Sets the screen to return to if the user cancels this menu. If previous is null, there will be no "Cancel" button.

Parameters:
previous - is the screen to go to if the user presses "Cancel".

appendMenuOption

public void appendMenuOption(MenuItem option)
Appends a new menu option to this menu.

Parameters:
option - is the menu item to add.

appendMenuOption

public void appendMenuOption(DeviceScreen option)
Appends a screen as a menu option. If selected the screen will be shown. The screen's title is used as its text.

Parameters:
option - is screen to add as a menu item.

appendMenuOption

public void appendMenuOption(java.lang.String text,
                             DeviceScreen option)
Appends a screen as a menu option. If selected the screen will be shown.

Parameters:
text - is string that appears in the menu option.
option - is screen to add as a menu item.

appendSubmenu

public void appendSubmenu(Menu submenu)
Appends another menu as a menu option. The submenu will have an arrow next to it to indicate to the user it is another menu.

To use a Menu as a screen and not a submenu call the appendMenuOption method instead.

Parameters:
submenu - is the screen to add as a menu item.

declineNotify

protected void declineNotify()
The left menu button takes the user back to the previous screen. If there is no previous screen it has no effect.

Overrides:
declineNotify in class DeviceScreen
See Also:
DeviceScreen.getLeftMenuText()

acceptNotify

protected void acceptNotify()
The right menu button selects the highlighted menu item.

Overrides:
acceptNotify in class DeviceScreen
See Also:
DeviceScreen.getRightMenuText()

keyPressed

protected void keyPressed(int key)
Responds to key press events that are specific to menu screens. Selects the highlighted menu choice if the joystick's FIRE key is pressed. Scrolls from the last choice to the first choice if DOWN is pressed and from the first to the last if UP is pressed.

Overrides:
keyPressed in class Dialog
Parameters:
key - is the key code of the button the user pressed.