Developers
Local Navigation
Richard Evers, Editor
Most applications can be written using a fairly common subset of the available API. To follow is a brief tutorial on the most commonly used methods from the BlackBerry and MIDP APIs.
| Package | Class | Method |
|---|---|---|
| javax.microedition.io | Connector | open |
| net.rim.device.api.ui.component | DateField | ( constructor ) |
| net.rim.device.api.ui.component | DateField | GetDate |
| net.rim.device.api.ui.component | DateField | SetEditable |
| net.rim.device.api.ui.component | Dialog | Alert |
| net.rim.device.api.ui.component | Dialog | Ask |
| net.rim.device.api.ui.component | EditField | ( constructor ) |
| net.rim.device.api.ui.component | EditField | SetEditable |
| net.rim.device.api.ui.component | EditField | SetFilter |
| net.rim.device.api.ui | Graphics | DrawText |
| net.rim.device.api.ui | Graphics | DrawPoint |
| net.rim.device.api.ui | Graphics | getScreenWidth |
| net.rim.device.api.ui | Graphics | SetColor |
| net.rim.device.api.system | KeyListener | KeyDown |
| net.rim.device.api.system | KeyListener | KeyRepeat |
| net.rim.device.api.system | KeyListener | KeyStatus |
| net.rim.device.api.system | KeyListener | KeyUp |
| net.rim.device.api.ui.component | LabelField | ( constructor ) |
| net.rim.device.api.ui.container | MainScreen | NextFocus |
| net.rim.device.api.ui | MenuItem | ( constructor ) |
| net.rim.device.api.ui.component | ObjectChoiceField | ( constructor ) |
| net.rim.device.api.ui.component | ObjectChoiceField | setChangeListener |
| net.rim.device.api.ui.component | ObjectChoiceField | getChoice |
| net.rim.device.api.ui.component | ObjectChoiceField | setChoices |
| net.rim.device.api.ui.component | ObjectChoiceField | setSelectedIndex |
| net.rim.device.api.ui.component | ObjectChoiceField | getSize |
| net.rim.device.api.util | Persistable | |
| javax.microedition.rms | RecordStore | addRecord |
| javax.microedition.rms | RecordStore | closeRecordStore |
| javax.microedition.rms | RecordStore | deleteRecordStore |
| javax.microedition.rms | RecordStore | enumerateRecords |
| javax.microedition.rms | RecordStore | openRecordStore |
| net.rim.device.api.i18n | ResourceBundle | getBundle |
| net.rim.device.api.i18n | ResourceBundle | getString |
| net.rim.device.api.system | TrackwheelListener | trackWheelClick |
| net.rim.device.api.system | TrackwheelListener | trackWheelRoll |
| net.rim.device.api.system | TrackwheelListener | trackWheelUnclick |
| net.rim.device.api.ui | UiApplication | enterEventDispatcher |
| net.rim.device.api.ui | UiApplication | getActiveScreen |
| net.rim.device.api.ui | UiApplication | getUiApplication |
| net.rim.device.api.ui | UiApplication | invokeLater |
| net.rim.device.api.ui | UiApplication | PopScreen |
| net.rim.device.api.ui | UiApplication | pushScreen |
javax.microedition.io.Connector.open()
Description:
- Basic type of generic connection.
- Used to create and open most connection types including HTTP, SMS and file.
Syntax:
public static Connection open(String URL)
Parameter:
URL: connection string
Returns:
new Connection object
Throws:
- IllegalArgumentException if a parameter is invalid
- ConnectionNotFoundException if connection not found
- IOException if some other kind of I/O error occurs
Example:
public static final String httpURL = "http://www.mywebsite.com";
HttpConnection http = null;
synchronized(this) {
try {
//create an HTTP connection with
// an InputStream
http = (HttpConnection)Connector.open(httpURL);
http.setRequestMethod(HttpConnection.POST);
net.rim.device.api.ui.component.DateField()
Description:
Constructs a new DateField instance with label, initial value, and format.
Syntax:
public DateField
(
String field_label,
long initial_date,
DateFormat format
)
Parameters:
- Field Label
- Initial date value
- Format to specify how the value looks: DATE (year, month, day) TIME (hour, minute, second) DATE_TIME (yr, month, day, hour, min, sec)
Returns:
DateField
Example:
// set date
long date = _receipt.getDateAsLong();
if ( date == 0 )
date = Calendar.getInstance().getTime().getTime();
_dateField = new DateField(_resources.getString(EXP_DATE), date,DateField.DATE);
net.rim.device.api.ui.component.DateField.getDate()
Description:
- Retrieves the absolute value of field in ticks
- Returns number of milliseconds since the epoch (midnight Jan 1, 1970) represented by field's date
Syntax:
public long getDate()
Parameter:
void
Returns:
- If time represented in field, returns value between 0 and (24*60*60*1000)
- If field's value is unspecified, returns Long.MIN_VALUE
Example:
private boolean saveSettings() {
_receipt.setDate(_dateField.getDate());
net.rim.device.api.ui.component.DateField.setEditable()
Description:
- Sets editable state of field
- Overrides setEditable in class Field
Syntax:
public void setEditable(boolean editable)
Parameter:
editable (true == editable, false == read only)
Returns:
void
Example:
_dateField.setEditable(true);
add(_dateField);
net.rim.device.api.ui.component.Dialog.alert()
Description:
- Creates an alert dialog
- Uses an exclamation mark bitmap
Syntax:
public static void alert(String message)
Parameter:
Text message to display in the alert
Returns:
void
Example:
Dialog.alert(_resources.getString(ERROR_CONNECTION));
net.rim.device.api.ui.component.Dialog.ask()
Description:
- Creates a standard inquiry dialog
- Uses a question mark bitmap
Syntax:
public static int ask(int type)
Parameter:
Standard inquiry dialog type:
D_OK
D_SAVE
D_DELETE
D_YES_NO
Returns:
Integer set as follows:
Dialog.SAVE
Dialog.CANCEL
Dialog.DISCARD
Example:
int response = Dialog.ask(Dialog.D_SAVE);
if (Dialog.SAVE == response || Dialog.CANCEL == response)
return false;
if ( Dialog.DISCARD == response )
_report.deleteReceipt(_receiptId);
net.rim.device.api.ui.component.EditField()
Description:
Builds an Field.EDITABLE edit field with a specified label and initial contents that can hold up to BasicEditField.DEFAULT_MAXCHARS characters
Syntax:
public EditField(String label, String initialValue)
Parameters:
- Field label
- Initial text value to show in field
Returns:
EditField
Example:
private void addFields() {
_emailField = new EditField(_resources.getString( FIELD_USER_EMAIL ),_reportDatastore.getUserEmail());
net.rim.device.api.ui.component.EditField.setEditable()
Description:
- Set editable state of field
- Change style by adding or removing EDITABLE style
- Method inherited from class net.rim.device.api.ui.Field
Syntax:
public void setEditable(boolean editable)
Parameter:
editable == True then make field editable
editable == False then make non-editable
Returns:
void
Example:
_emailField.setEditable(true);
add(_emailField);
net.rim.device.api.ui.component.EditField.setFilter()
Description:
- Sets the text filter for field
- Method inherited from class net.rim.device.api.ui.component.BasicEditField
Syntax:
public void setFilter(TextFilter filter)
Parameter:
Text filter for field:
DEFAULT
HEXADECIMAL
INTEGER
LOWERCASE
NUMERIC
PHONE
UPPERCASE
URL
Returns:
void
Example:
_emailField = new EditField(_resources.getString(FIELD_USER_EMAIL), _reportDatastore.getUserEmail());
_emailField.setFilter(EMAIL);
net.rim.device.api.ui.Graphics.drawText()
Description:
- Use to draw a text character
- Renders character's glyph using default font
- Crops to fit if glyph too large for current clipping region
Syntax:
public int drawText(char character, int x, int y, int flags, int width)
Parameters:
- Character to draw
- Horizontal (x) and Vertical (y) positions of drawing anchor
- Combination of constant drawing position flags
- Width, in pixels, of region available for drawing
Returns:
Glyph block width in pixels including width of clipped pixels
Example:
public void paint( Graphics graphics, int yPos ) {
int xpos = 0;
int n = _spaces.length;
for (int i = 0; i < n; ++i) {
graphics.drawText( _texts[i], xpos, yPos, graphics.ELLIPSIS, _spaces[i] );
xpos += _spaces[i];
if (i < n - 1)
xpos += _buffer;
}
}
net.rim.device.api.ui.Graphics.drawPoint()
Description:
Draws a pixel at passed coordinate
Syntax:
public void drawPoint(int x, int y)
Parameters:
- Horizontal (x) position of the point to draw
- Vertical (y) position of the point to draw
Returns:
void
Example:
// p
le
// this gives us a greyed out effect.
protected void subpaint(Graphics graphics) {
super.subpaint(graphics);
if (!_focusable) {
graphics.setColor(Graphics.WHITE);
int w = getWidth();
int h = getHeight();
for (int i=0; i < w ;++i) {
for (int c=0; c < h; ++c) {
if ((i+c)%2 == 0 ) {
graphics.drawPoint(i,c);
}
}
}
graphics.setColor(Graphics.BLACK);
}
}
net.rim.device.api.ui.Graphics.SetColor()
Description:
- Sets the current color
- All subsequent rendering done in displayable color nearest to specified color
Syntax:
public void setColor(int RGB)
Parameter:
RGB color to use, of the form 0x00RRGGBB
Returns:
void
Example:
protected void subpaint(Graphics graphics) {
super.subpaint(graphics);
if (!_focusable) {
graphics.setColor(Graphics.WHITE);
int w = getWidth();
int h = getHeight();
for (int i=0; i < w ;++i) {
for (int c=0; c < h; ++c) {
if ((i+c)%2 == 0 ) {
graphics.drawPoint(i,c);
}
}
}
graphics.setColor(Graphics.BLACK);
}
}
net.rim.device.api.ui.Graphics.getScreenWidth()
Description:
Retrieves total drawing width of the screen
Syntax:
public static int getScreenWidth()
Parameter:
void
Returns:
Width in pixels of the device screen's drawable area
Example:
public int getPreferredWidth( ListField listField) {
return Graphics.getScreenWidth();
}
net.rim.device.api.system.KeyListener.keyDown()
Description:
- Invoked when a key has been pressed.
- Using Keypad.key(keycode) gets the key pressed; alphabetic keys are always upper case.
- Using keypad.status(keycode) gets the modifier key status at the time of the keypress.
- Applications such as games will want to use this function as it provides information about which key was actually pressed, regardless of locale and any key mappings applied.
Syntax:
public boolean keyDown( int keycode, int time )
Parameters:
- Key scan code of the character before any effects of the ALT or SHIFT keys
- Number of milliseconds since the device was turned on
Returns:
True if the event was consumed
Example:
public boolean keyDown(int keycode,int time) {
return false;
}
net.rim.device.api.system.KeyListener.keyRepeat()
Description:
- Invoked when a key has been repeated
- Similar to keyDown
Syntax:
public boolean keyRepeat( int keycode, int time )
Parameters:
- Key scan code before effects of ALT or SHIFT keys
- Number of milliseconds since device was turned on
Returns:
True if event was consumed
Example:
public boolean keyRepeat( int keycode, int time ) {
return false;
}
net.rim.device.api.system.KeyListener.keyStatus()
Description:
Invoked when ALT or SHIFT status has changed
Syntax:
public boolean keyStatus( int keycode, int time )
Parameters:
- Key scan code before effects of ALT or SHIFT keys
- Number of milliseconds since device was turned on
Returns:
True if event was consumed
Example:
public boolean keyStatus( int keycode, int time ) {
return false;
}
net.rim.device.api.system.KeyListener.keyUp()
Description:
- Invoked when a key has been released
- Events are disabled by default for performance reasons and must be explicitly enabled via Application.enableKeyUpEvents(boolean)
Syntax:
public boolean keyUp( int keycode, int time )
Parameters:
- Key scan code before effects of ALT or SHIFT keys
- Number of milliseconds since device was turned on
Returns:
True if event was consumed
Example:
public boolean keyUp( int keycode, int time ) {
return false;
}
net.rim.device.api.ui.component.LabelField()
Description:
Constructs a new LabelField instance with initial text
Syntax:
public LabelField(Object text)
Parameter:
Label text: can be a String, StringBuffer, char[] or byte[] and may be null for an empty label
Returns:
void
Example:
// Constructs a new ReportScreen object,
// and populates the screen with all the
// available information
public ReportScreen(ReportDataStore rds) {
_reportDatastore = rds;
setTitle(new LabelField(_resources.getString(TITLE_MAIN)));
_list = new ListField();
_list.setCallback(new CallBack());
// add the list field to the screen
add(_list);
net.rim.device.api.ui.container.MainScreen.nextFocus()
Description:
- Returns index of the next field to be given focus
- Called by framework during TW (track wheel) focus move operation
- Method inherited from class net.rim.device.api.ui.Manager
Syntax:
protected int nextFocus(int direction, boolean alt)
Parameters:
- Direction focus is moving within field (+1 forward, -1 back)
- True if ALT-rolling the trackwheel else false
Returns:
Index of next field to have focus (-1 to exit)
Throws:
IllegalArgumentException if direction parm != 1 or -1
Example:
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.*;
abstract class MainScreenWithMenus extends MainScreen {
abstract public MenuItem[] getMenuItems();
public int nextFocus( int direction, boolean alt ) {
return super.nextFocus(direction, alt);
}
}
net.rim.device.api.ui.MenuItem()
Description:
Constructs a new MenuItem
Syntax:
public MenuItem( ResourceBundle bundle, int id, int ordinal, int priority )
Parameters:
- Resource bundle to support internationalization
- Menu item ID / key value for menu item's associated resource bundle string
- Ordering parameter, lower values towards top of menu
- Priority of menu item
Returns:
void
Example:
menuItems[index++] = new MenuItem( _resources, MENUITEM_CLOSE, 200000, 20000 ) {
public void run() {
if (exit()) {
((ExpenseScreen)UiApplication.getUiApplication().getActiveScreen()).exit();
}
}
};
net.rim.device.api.ui.component.ObjectChoiceField()
Description:
- Builds a new object choice field, and sets the initially selected value based on index parameter
- If passed array is null then method ignores index parameter and sets initially selected index to zero
Syntax:
public ObjectChoiceField( String label, Object[] choices, int initialIndex )
Parameters:
- Field label
- Field choices - if null, empty object choice field is created
- Index of the initially selected value
Returns:
void
Example:
private int _currentType;
private void initTypeChoices() {
_typeChoices = new String[6];
_typeChoices[Receipt.MEALS] = "Expense Type Meals";
...
}
_typeField = new ObjectChoiceField( _resources.getString(FIELD_EXPENSE_TYPE), _typeChoices, _currentType );
net.rim.device.api.ui.component.ObjectChoiceField.getChoice()
Description:
- Retrieves object by index
- Overrides getChoice in class ChoiceField
Syntax:
public Object getChoice(int index)
Parameter:
Index position in list of object you wish to retrieve
Returns:
Object at the index you specify
Throws:
IllegalArgumentException
Example:
// cannot use
// ChoiceField.setSelectedIndex(Object)
// because it does not invalidate the field
private int getChoiceIndex(ObjectChoiceField field, Object obj) {
for (int i=field.getSize()-1;i>=0;--i) {
if (field.getChoice(i).equals(obj))
return i;
}
return -1;
}
net.rim.device.api.ui.component.ObjectChoiceField.setSelectedIndex()
Description:
Sets the currently chosen value
Syntax:
public void setSelectedIndex(int index)
Parameter:
Index of the selected value
Returns:
void
Throws:
IllegalArgumentException if index is out of bounds
Example:
switch (f.getSelectedIndex()) {
case Receipt.MILEAGE:
_gvf.setFocusable(false);
case Receipt.HOTEL:
case Receipt.TRANSPORTATION: {
int index = getChoiceIndex(_glField, otherChoice);
if (index != -1)
_glField.setSelectedIndex(index);
break;
}
net.rim.device.api.ui.component.ObjectChoiceField.getSize()
Description:
Retrieves number of choices in field
Syntax:
public int getSize()
Parameter:
void
Returns:
Number of choice values in field's list
Example:
// cannot use
// ChoiceField.setSelectedIndex(Object)
// because it does not invalidate the field
private int getChoiceIndex(ObjectChoiceField field, Object obj) {
for (int i=field.getSize()-1;i>=0;--i) {
if (field.getChoice(i).equals(obj))
return i;
return -1;
}
net.rim.device.api.ui.component.ObjectChoiceField.setChangeListener()
Description:
- Specifies a listener for field changes
- Method inherited from class net.rim.device.api.ui.Field
- Each field can have only one change listener object
- To provide a new change listener for a field, first invoke setChangeListener(null)
Syntax:
public void setChangeListener(FieldChangeListener listener)
Parameter:
Object to listen for field changes
Returns:
void
Throws:
IllegalStateException when listener already set and !null
Example:
ChoiceFieldListener CFL = new ChoiceFieldListener();
...
_glField.setChangeListener(CFL);
net.rim.device.api.ui.component.ObjectChoiceField.setChoices()
Description:
- Provides a new list of choices for field
- Selected choice reset to first value in the list
Syntax:
public void setChoices(Object[] choices)
Parameter:
New list of choices for field
Returns:
void
Example:
public void refresh() {
// an existing receipt
if (_receiptId>=0) {
if (_receipt.getGLCode() !=_glField.getChoice(0)) {
_glField.setChoices(getListAsArray(_glCodeList, _receipt.getGLCode()));
}
}
}
javax.microedition.rms.RecordStore.addRecord()
Description:
Adds a new record to persistent storage before returning
Syntax:
public int addRecord(byte[] data, int offset, int numBytes)
Parameters:
- Data to be stored in record: null for no data
- Index into data buffer of first relevant byte for record
- Number of bytes of data buffer to use for record (>=0)
Returns:
recordId for new record
Throws:
- RecordStoreNotOpenException if record store is not open
- RecordStoreException if related exception occurred
- RecordStoreFullException if has no more room
Example:
try {
// open the rms, add the record,
// and close the rms
RecordStore rms = RecordStore.openRecordStore( name, true );
rms.addRecord(data, _start, data.length);
rms.closeRecordStore();
} catch (Exception e) {
javax.microedition.rms.RecordStore.closeRecordStore()
Description:
- Called when MIDlet requests record store closure
- Not closed until closeRecordStore() count equals openRecordStore() count
- All listeners removed on close
Syntax:
public void closeRecordStore()
Parameter:
void
Returns:
void
Throws:
- RecordStoreNotOpenException if record store is not open.
- RecordStoreException if related exception occurred
Example:
try {
RecordStore rms = RecordStore.openRecordStore(name, true);
RecordEnumeration enum = rms.enumerateRecords(null,null, false );
if (enum.hasNextElement())
result = enum.nextRecord();
else
result = null;
rms.closeRecordStore();
enum.destroy();
} catch (Exception e) {
javax.microedition.rms.RecordStore.deleteRecordStore()
Description:
- Deletes named record store
- MIDlet suites only allowed to operate on their own record stores, including deletions
Syntax:
public static void deleteRecordStore(String recStoreName)
Parameter:
The MIDlet suite unique record store to delete
Returns:
void
Throws:
- RecordStoreNotOpenException if record store is not open.
- RecordStoreException if related exception occurred
Example:
static boolean save( byte[] data, String name ) {
try {
RecordStore.deleteRecordStore(name);
} catch (RecordStoreException rse) {
}
javax.microedition.rms.RecordStore.enumerateRecords()
Description:
- Returns an enumeration for traversing a set of records in the record store in an optionally specified order
- The filter, if non-null, is used to determine what subset of the record store records will be used
- If both the filter and comparator are null, enumeration will traverse all records in the store in an undefined order
Syntax:
public RecordEnumeration enumerateRecords( RecordFilter filter, RecordComparator comparator, boolean keepUpdated )
Parameters:
- RecordFilter is an interface with one method, boolean matches(byte[] candidate)
- RecordComparator is an interface with one method, int compare(byte[] rec1, byte[] rec2)
- The keepUpdated parameter tells whether the enumeration has to keep track of inserts and deletes that happen while the enumeration is open
Returns:
All records for which the filter returns true, in the order defined by the RecordComparator
Throws:
RecordStoreNotOpenException if record store is not open
Example:
try {
RecordStore rms = RecordStore.openRecordStore(name, true);
RecordEnumeration enum = rms.enumerateRecords(null,null, false );
if (enum.hasNextElement())
result = enum.nextRecord();
else
result = null;
rms.closeRecordStore();
enum.destroy();
} catch (Exception e) {
javax.microedition.rms.RecordStore.openRecordStore()
Description:
Open/Create a record store associated with MIDlet suite
Syntax:
public static RecordStore openRecordStore( String recordStoreName, boolean createIfNecessary )
Parameters:
- MIDlet suite unique name (max 32 char length)
- If true, record store will be created if necessary
Returns:
If method called when record store is already open by a MIDlet in the MIDlet suite, returns a reference to the same object
Throws:
- RecordStoreException if a record store-related exception occurred
- RecordStoreNotFoundException if record store could not be found
- RecordStoreFullException if record store is full
Example:
try {
RecordStore rms = RecordStore.openRecordStore(name, true);
RecordEnumeration enum = rms.enumerateRecords(null,null, false );
if (enum.hasNextElement())
result = enum.nextRecord();
else
result = null;
rms.closeRecordStore();
enum.destroy();
} catch (Exception e){
net.rim.device.api.i18n.ResourceBundle.getBundle()
Description:
- Retrieve resource bundle family with bundle ID
- Creates new family with ID and name if necessary
Syntax:
public static final ResourceBundleFamily getBundle(long bundle, String name)
Parameters:
- Bundle ID
- Name for the resource bundle family
Returns:
Resource bundle family of provided ID
Throws:
IllegalArgumentException if name or its hash is not valid
Example:
public static MenuItem _closeMenuItem;
private static ResourceBundle _resources;
static {
//Resources for the project
_resources = ResourceBundle.getBundle(BUNDLE_ID, BUNDLE_NAME);
// Close Menu Item
_closeMenuItem = new MenuItem( _resources, MENUITEM_BACK, 200000, 10 ) {
public void run() {
UiApplication uiApp = UiApplication.getUiApplication();
UiApplication.getUiApplication().popScreen(uiApp.getActiveScreen());
}
};
net.rim.device.api.i18n.ResourceBundle.getString()
Description:
- Retrieves string form of resource object by key
- Method casts return value of getObject(int) as a String
Syntax:
public final String getString(int key)
Parameter:
Key for searched-for resource object
Returns:
String form of resource object
Throws:
MissingResourceException if neither bundle nor any enclosing parent bundle contains resource associated with provided key
Example:
private static String[] _ccStartItems = {
_resources.getString(GL_CAT_CORPORATE),
_resources.getString(GL_CAT_IT),
_resources.getString(GL_CAT_RD),
_resources.getString(GL_CAT_BBSM),
_resources.getString(GL_CAT_MFG)
};
net.rim.device.api.system.TrackwheelListener.trackwheelClick()
Description:
Invoked when the trackwheel is clicked
Syntax:
public boolean trackwheelClick(int status, int time)
Parameters:
- Modifier key status
- Ticks since device reset
Returns:
True if the event was consumed; otherwise, false
Example:
public boolean trackwheelClick( int status, int time ) {
Menu menu = new Menu();
makeMenu( menu );
menu.show();
return true;
}
net.rim.device.api.system.TrackwheelListener.trackwheelUnclick()
Description:
Invoked when the trackwheel is released
Syntax:
public boolean trackwheelUnclick(int status, int time)
Parameters:
- Modifier key status
- Ticks since device reset
Returns:
True if the event was consumed; otherwise, false
Example:
public boolean trackwheelUnclick( int status, int time ) {
return false;
}
net.rim.device.api.system.TrackwheelListener.trackwheelRoll()
Description:
Invoked when the trackwheel is rolled
Syntax:
public boolean trackwheelRoll(int amount, int status, int time)
Parameters:
- Amount trackwheel has rotated since last event Negative values indicate an upwards (or backwards) roll Positive values indicate a downwards (or forwards) roll
- Modifier key status
- Ticks since device reset
Returns:
True if the event was consumed; otherwise, false
Example:
public boolean trackwheelRoll(int amount,int status,int time) {
return false;
}
net.rim.device.api.ui.UiApplication.enterEventDispatcher()
Description:
- Enters the event dispatcher
- The thread that calls this method (typically main application thread) becomes the event-dispatching thread, which will execute all drawing and event-handling code
- Under normal circumstances this method does not return
- Method inherited from class net.rim.device.api.system.Application
Syntax:
public void enterEventDispatcher()
Parameter:
void
Returns:
void
Example:
class ExpenseReporterMain extends UiApplication {
// main create a new instance of
// the main app and add it to the
// event dispatcher
public static void main(String args[])
{
ExpenseReporterMain app = new ExpenseReporterMain();
app.enterEventDispatcher();
}
net.rim.device.api.ui.UiApplication.getActiveScreen()
Description:
- Retrieve the topmost screen on the display stack (the currently active screen)
- Specified by getActiveScreen in interface UiEngine
Syntax:
public final Screen getActiveScreen()
Parameter:
void
Returns:
Active screen, or null if the display stack has no screens
Example:
if (RMSAccessor.save(b, ExpenseReporterUtil.DBNAME)) {
UiApplication uiApp = UiApplication.getUiApplication();
uiApp.popScreen(uiApp.getActiveScreen());
uiApp.popScreen(uiApp.getActiveScreen());
System.exit(0);
}
net.rim.device.api.ui.UiApplication.getUiApplication()
Description:
Retrieves this UI application object
Syntax:
public static final UiApplication getUiApplication()
Parameter:
void
Returns:
This UI application
Example:
static {
//Resources for the project
_resources = ResourceBundle.getBundle(BUNDLE_ID, BUNDLE_NAME);
// Close Menu Item
_closeMenuItem = new MenuItem( _resources, MENUITEM_BACK, 200000,10 ) {
public void run() {
UiApplication uiApp = UiApplication.getUiApplication();
UiApplication.getUiApplication().PopScreen(uiApp.getActiveScreen());
}
};
}
net.rim.device.api.ui.UiApplication.invokeLater()
Description:
- Put runnable object into this application's event queue
- Invoke this method, passing a runnable object, to have that object's run() method invoked on the dispatch thread, after all pending events are processed
- Method inherited from class net.rim.device.api.system.Application
Syntax:
public final void invokeLater(Runnable runnable)
Parameter:
Runnable object to be placed on the dispatch thread's queue of events to execute
Returns:
void
Example:
Transport conn = new Transport();
conn.start();
synchronized(this) {
_results = conn.getCodes(_superCode);
if (_results != null && _results.getAt(0) != null) {
updateList(_results.size());
} else {
updateList(0);
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
Dialog.alert(_resources.getString(ERROR_CONNECTION));
}
});
}
}
net.rim.device.api.ui.UiApplication.popScreen()
Description:
- Removes screen from display stack then updates screen
- Specified by popScreen in interface UiEngine
Syntax:
public final void popScreen(Screen screen)
Parameter:
Screen to remove
Returns:
void
Throws:
IllegalArgumentException if screen not on stack
Example:
if (RMSAccessor.save(b, ExpenseReporterUtil.DBNAME)) {
UiApplication uiApp = UiApplication.getUiApplication();
uiApp.popScreen(uiApp.getActiveScreen());
uiApp.popScreen(uiApp.getActiveScreen());
System.exit(0);
}
net.rim.device.api.ui.UiApplication.pushScreen()
Description:
- Pushes screen onto the display stack then paints it
- Method is non-blocking and returns immediately
- Will cause a layout and paint so add all screen controls before pushing it
- Specified by pushScreen in interface UiEngine
Syntax:
public final void pushScreen(Screen screen)
Parameter:
Screen to push
Returns:
void
Example:
new MenuItem( _resources, MENUITEM_EXPENSE_GET_CC, 100, 100 ) {
public void run() {
if (_new) {
saveSettings();
}
CodeGrabberScreen cgs = new CodeGrabberScreen(_ccCode);
UiApplication.getUiApplication().pushScreen(cgs);
setDirty(true);
}
};