PDAP Application Life Cycle

PDAP is a complete superset of MIDP. As for MIDP, PDAP applications are based on the MIDlet class and share the MIDlet life cycle, as illustrated in Figure 3.1. However, PDAP contains several additional packages. For example, the AWT classes allow much more sophisticated user interfaces than lcdui, giving the programmer fine-grained control over component layout.

In this chapter, we will concentrate on the user interface enhancements of PDAP.

HelloPdap Revisited

The HelloPdap example from Chapter 1, “Java 2 Micro Edition Overview,” is already a complete PDAP application. Now that you have the necessary foundation, you can revisit HelloPdap from an API point of view.

First, you import the necessary midlet and awt packages:

import java.awt.*;
import javax.microedition.midlet.*;

Like all PDAP applications, the HelloPdap example is required to extend the MIDlet class:

public class HelloPdap extends MIDlet {

In the constructor, you create a Frame titled "HelloPdap":

Frame frame;

public HelloPdap () {
   frame = new Frame ("HelloPdap");
}

You do not add content to the frame yet, so only the title will be displayed. (A description of the awt classes is contained in the “PDA User Interface” 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, the show() method of the frame is called, requesting that the frame be displayed. If the frame is already visible, it is brought to the foreground:

public void startApp() {
   frame.show ();
}

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 startApp() and pauseApp(), the implementation of destroyApp() is mandatory. Here, we dispose of the frame, freeing the associated system resources:

    public void destroyApp(boolean unconditional) {
        frame.dispose ();
    }
}
					

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset