Archive for the ‘Mobile Computing’ Category



When a user interacts with a MIDlet loaded on a mobile information device, some events are generated. For example, if the user selects Save from the File menu, the application is notified of this action and responds to the generated event.

But how does the application get notified of an event, and how does it handle it?

Ans: There are two MIDP user interface APIs: high-level and low-level. Therefore, there are two kinds of events: high-level (such as selecting an item from a list) and low-level (such as pressing a key on the device).

Basics: Callbacks

When a user interacts with a MIDlet, events are generated and the application is modified to handle and respond to these events. The application is notified of such events through callbacks.

Thus, Callbacks are invocation of programmer-defined methods that are executed by the application in response to actions taken by a user at run time.

Callbacks are used in many programming environments, For example, the Abstract Window Toolkit (AWT) API makes heavy use of callbacks. When a user interacts with a component, for example, the interface code calls back the computational code to respond to the user’s action. Thus, when a user selects an item from a pull-down menu, the interface code for the menu will call back the computational code to invoke the selected item from the menu.

There are four kinds of user interface callbacks in MIDP:

  • Abstract commands that are part of the high-level API.
  • Low-level events that represent single key presses and releases.
  • Calls to the paint() method of a Canvas class.
  • Calls to a Runnable object’s run method requested by a call to the callSerially method of the Display class.

Screen Navigation

As a MIDlet developer, you are responsible for providing a way for the user to navigate the different screens that make up your MIDlet. The javax.microedition.lcdui package provides the Command class.

The Command class encapsulates the semantic information of an action. The command itself contains only information about a command, but not the actual action that happens when a command is activated. The action is defined in a CommandListener object associated with the screen.

Handling High-Level Events

Handling events in the high-level API is based on a listener model. Screen and Canvas objects can have listeners for commands. For an object to be a listener, it must implement the CommandListener interface.

You add commands to a displayable object with the addCommand method, and register a listener with the setCommandListener method. Both of these methods are part of the Displayable class and they are inherited by Screen and Canvas.

Example: Handling High-Level Events

A list of items  is created. The prepare() method is called whenever an item is selected. The testItem# methods, where # is a number between 1 and 4, call the prepare method and set the name of the menu.

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class EventEx1 extends MIDlet
implements CommandListener {
// display manager
Display display = null;

// a menu with items
List menu = null; // main menu

// textbox
TextBox input = null;

// command
static final Command backCommand =
new Command("Back", Command.BACK, 0);
static final Command mainMenuCommand =
new Command("Main", Command.SCREEN, 1);
static final Command exitCommand =
new Command("Exit", Command.STOP, 2);
String currentMenu = null;

// constructor.
public EventEx1() {

* Start the MIDlet by creating a list of items
* and associating the exit command with the list.
public void startApp()
throws MIDletStateChangeException {
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);


public void pauseApp() {
display = null;
menu = null;
input = null;

public void destroyApp(boolean unconditional) {

// main menu
void mainMenu() {
currentMenu = "Main";

* a generic method that is called when any of
* the items on the list are selected.
public void prepare() {
input = new TextBox("Enter some text: ",
"", 5, TextField.ANY);

* Test item1.
public void testItem1() {
currentMenu = "item1";

* Test item2.
public void testItem2() {
currentMenu = "item2";

* Test item3.
public void testItem3() {
currentMenu = "item3";

* Test item4.
public void testItem4() {
currentMenu = "item4";

* Handle events.
public void commandAction(Command c, Displayable d) {
String label = c.getLabel();
if (label.equals("Exit")) {
} else if (label.equals("Back")) {
if(currentMenu.equals("item1") ||
currentMenu.equals("item2") ||
currentMenu.equals("item3") ||
currentMenu.equals("item4"))  {
// go back to menu
} 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;


File > New Project>  MIDP Application > Next > Project Name > Finish > Run


Java ME Platform SDK is a toolbox for developing mobile applications. It provides device emulation, a standalone development environment, and a set of utilities for rapid development of mobile applications.

On Windows, Java ME SDK 3.0 is the successor to the popular Java Wireless Toolkit 2.5.2 and Java Toolkit 1.0 for CDC. It integrates CLDC technology into one SDK. The Java ME SDK 3.0 is now available for Windows XP and Vista 32-bit, and for the Mac OS

Key Features
The Java ME SDK provides device emulation, a standalone development environment, and a set of utilities for rapid development of Java ME applications. It provides the following features, which are described in detail below:

  • Integration with third-party emulators and Windows Mobile devices.

The new Java ME Platform SDK architecture allows integration of 3rd party emulators and devices. Java ME Platform SDK comes with Sun’s Java runtime environment for Windows Mobile. A user can install this runtime on a Windows Mobile device or a Microsoft device emulator and experience all the on-device features of Java ME Platform SDK.

  • On-device deployment and on-device debugging.
  • New development environment based on Netbeans Platform.
  • Device search database integrated in SDK.
  • JavaFX Mobile Emulator included.


  1. Verify that your system meets the preceding minimum hardware (1 GB RAM) and software requirements.
  2. Download and install Java ME Platform SDK 3.0. from http://java.sun.com/javase/downloads/index.jsp
  3. Download and install Quick Time Player from http://www.apple.com/quicktime/download/
  4. Download and install Java Platform Micro Edition Software Development Kit 3.0 for Windows from http://java.sun.com/javame/downloads/sdk30.jsp
  5. Double-click the executable file to start the installation, and follow the prompts.
  6. As the installation concludes, the Device Manager appears in the Windows system tray.

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 50 other followers

What I am Upto Now

Follow Me On Twitter

Blog Stats

  • 80,851 hits

Live Traffic

My Paintings

%d bloggers like this: