Create A Menu Item - Blackberry JAVA DEVELOPMENT ENVIRONMENT - - DEVELOPMENT GUIDE Manual

Version: 4.7.0
Hide thumbs Also See for JAVA DEVELOPMENT ENVIRONMENT - - DEVELOPMENT GUIDE:
Table of Contents

Advertisement

Development Guide
public String getLabel() {
return _label;
}
public int getShape() {
return _shape;
}
public void setLabel(String label) {
_label = label;
_labelWidth = _font.getAdvance(_label);
updateLayout();
}
public void setShape(int shape) {
_shape = shape;
}

Create a menu item

1.
Import the following classes:
• net.rim.blackberry.api.menuitem.ApplicationMenuItem
• java.lang.IllegalStateException
• net.rim.device.api.ui.component.Dialog
2.
Import the javax.microedition.pim.Contact interface.
3.
Extend the abstract ApplicationMenuItem class to define a menu item.
public class SampleMenuItem extends ApplicationMenuItem { ... }
4.
Invoke ApplicationMenuItem() to specify the position of the menu item in the menu. A higher number means
that the menu item appears lower in the menu.
SampleMenuItem() {
super(20);
}
5.
Implement toString() to specify the menu item text. In the following code sample, we implement toString() to
display the text "Open the Contacts Demo application" in the menu of the BlackBerry® device application.
public String toString() {
return "Open the Contacts Demo application";
}
6.
Implement run() to specify the behaviour of the menu item. In the following code sample, if a BlackBerry device user
clicks the text "Open the Contacts Demo application" in the menu of the BlackBerry device application, if a Contact
exists, we allow an application called ContactsDemo to receive events by invoking
ContactsDemo.enterEventDispatcher().
public Object run(Object context) {
Contact c = (Contact)context; // An error occurs if this does not work.
if ( c != null ) {
UI components
27

Advertisement

Table of Contents
loading

This manual is also suitable for:

Java development environment

Table of Contents