Menu sample app
The menu demo sample application demonstrates how to create a menu, then add the following customizations to it:
- An image or icon
- A submenu
- A different font
- A background color
- A border
This file defines four classes, MenuDemo, MenuDemoScreen, DemoMenuItem, and ImageMenuItem.
The MenuDemo class extends UiApplication to support a user interface and contains the following constructor and methods:
The MenuDemoScreen class extends MainScreen to create the screen of the application, and implements the FieldChangeListener interface to listen for changes in the state of the fields on the screen. The MenuDemoScreen class contains the following constructor, methods and classes:
The ImageMenuItem class extends MenuItem, and contains the following constructor:
This sample features the following classes:
This class provides a menu that is displayed when users press the Menu key. It consists of methods for populating the menu with objects (MenuItem objects, for example), and for customizing the appearance of the menu, (setFont(Font font), for example).
In the sample application, the menu is populated with MenuItem, SubMenu, and SeparatorField objects. Selecting the different options dynamically changes which objects are added to the menu, as well as how it looks.
This class creates submenus that are added to menus. The submenu is populated by MenuItem objects, that are added to the Menu object by invoking Menu.add(Submenu submenu).
In the sample application, the submenu is added to the menu object when you select the "Menu with sub menu" option. The submenu in the sample application is populated with DemoMenuItem objects, a subclass of MenuItem created in the sample application.
This class creates an object that represents an abstract menu item.
The sample application uses two subclasses of the MenuItem class, DemoMenuItem and ImageMenuItem. DemoMenuItem is created as an inner class, and demonstrates the SubMenu class by populating a SubMenu with DemoMenuItem objects. ImageMenuItem demonstrates how to add an image to menu items.
Install the sample app
In the BlackBerry Java Development Environment, open the workspace that you want to add the sample application to.
In the Files pane, right-click <workspace_name>.
Click Add project to <workspace_name>.
In the Add project to <workspace_name> dialog box, browse to the menudemo folder. The default location of this folder is C:\Program Files\Research In Motion\BlackBerry JDE 5.0.0\samples\com\rim\samples\device\ui\menudemo.
Click the MenuDemo.jdp file.
The sample app is also available in github.
Run the sample app
In the BlackBerry Java Development Environment, in the workspace that you added the MenuDemo project to, right-click MenuDemo.
Click Build project.
On the taskbar, click Start > Applications > Research In Motion > BlackBerry JDE 5.0.0 > Device Simulator.
On the Home screen of the BlackBerry Smartphone Simulator, on the screen, click All.
Click the Menu Demo icon.