Thursday, 2 October 2008

Java ME --> Mobile Information Device Profile (MIDP)

HelloMidp Revisited

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

Like all MIDP applications, the HelloMidp example is required to extend the MIDlet class:

public class HelloMidp extends MIDlet {

In the constructor, you obtain the Display and create a Form:

Display display;
Form mainForm;

public HelloMidp () {
mainForm = new Form ("HelloMidp");

A Form is a specialized Displayable class. The Form has a title that is given in the constructor. You do not add content to the form yet, so only the title will be displayed. (A detailed description of the Form class is contained in the next section.)

When your MIDlet is started the first time, or when the MIDlet resumes from a paused state, the startApp() method is called by the program manager. Here, you set the display to your form, thus requesting the form to be displayed:

public void startApp() {
display = Displayable.getDisplay (this);
display.setCurrent (mainForm);

When the application is paused, you do nothing because you do not have any allocated resources to free. However, you need to provide an empty implementation because implementation of pauseApp() is mandatory:

public void pauseApp() {

Like pauseApp(), implementation of destroyApp() is mandatory. Again, you don't need to do anything here for this simple application:

public void destroyApp(boolean unconditional) {

Reference :

No comments: