appmain
Class Hello

java.lang.Object
  |
  +--javax.microedition.midlet.MIDlet
        |
        +--appmain.Hello
All Implemented Interfaces:
javax.microedition.lcdui.CommandListener

public class Hello
extends javax.microedition.midlet.MIDlet
implements javax.microedition.lcdui.CommandListener

This class implements a minimal J2ME MIDlet to show the various life cycle methods and provide an example for working out the details of compiling, packaging, and running midlets. Besides, a Hello World program must exist in all environments in order for the universe to continue smoothly on its course.

The main class of a midlet extends javax.microedition.midlet.MIDlet.

The screen displays are created and managed by subclasses of the abstract base class Displayable such as List. A Displayable object may have commands and listeners associated with it.

Commands are mapped to various buttons on the device. This mapping is controlled by the Application Management Software in the device. The action taken in response to a command is controlled by the midlet with one or more classes that implement the CommandListener interface.

$Id: Hello.java,v 1.3 2003/04/01 06:01:26 finson Exp $


Constructor Summary
Hello()
          Create a new midlet based on the Hello class.
 
Method Summary
 void commandAction(javax.microedition.lcdui.Command c, javax.microedition.lcdui.Displayable d)
          Indicates that Command c has occurred on Displayable d.
protected  void destroyApp(boolean unconditional)
          Signals the MIDlet to terminate and enter the Destroyed state.
protected  void pauseApp()
          Signals the MIDlet to stop and enter the Paused state.
protected  void startApp()
          Signals the MIDlet that it has entered the Active state.
 
Methods inherited from class javax.microedition.midlet.MIDlet
getAppProperty, notifyDestroyed, notifyPaused, resumeRequest
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Hello

public Hello()
Create a new midlet based on the Hello class. Note that this constructor is called only once when the midlet is launched, and it should perform basic initialization. However, the midlet is not actually running and in control of the display until the life cycle method startApp() is called.

In this simple HelloWorld midlet, we just create a Displayable screen object of type List, add our text to it, add a Command and a CommandListener, and then return.

Method Detail

startApp

protected void startApp()
Signals the MIDlet that it has entered the Active state. In the Active state the MIDlet may hold resources. The Display is known to be ready for dedicated use at this point, so we get a reference to it and tell it to display the screen that we created earlier in the constructor.

Specified by:
startApp in class javax.microedition.midlet.MIDlet

commandAction

public void commandAction(javax.microedition.lcdui.Command c,
                          javax.microedition.lcdui.Displayable d)
Indicates that Command c has occurred on Displayable d. The user has selected one of the Commands that we made available for the currently displayed Displayable, so as a CommandListener, we are responsible for taking the appropriate action. Note that the system is essentially blocked while this method is executing, so this method should return very quickly. Long running tasks should be delegated to another thread.

Specified by:
commandAction in interface javax.microedition.lcdui.CommandListener
Parameters:
c - a Command object identifying the command. This is either one of the application's Commands that have been added to the Displayable with Displayable.addCommand(Command) or is the implicit SELECT_COMMAND of List.
d - the Displayable on which this event has occurred

pauseApp

protected void pauseApp()
Signals the MIDlet to stop and enter the Paused state. In the Paused state the MIDlet must release shared resources and become quiescent. This method will only be called called when the MIDlet is in the Active state.

Specified by:
pauseApp in class javax.microedition.midlet.MIDlet

destroyApp

protected void destroyApp(boolean unconditional)
Signals the MIDlet to terminate and enter the Destroyed state. In the destroyed state the MIDlet must release all resources and save any persistent state. This method may be called by the Application Management Software while the midlet is in the Paused or Active states. If the method is called from within the midlet itself, then the midlet should also call notifyDestroyed to let the AMS know that we are history.

Specified by:
destroyApp in class javax.microedition.midlet.MIDlet
Parameters:
unconditional - If true when this method is called, the MIDlet must cleanup and release all resources. If false the MIDlet may throw MIDletStateChangeException to indicate it does not want to be destroyed at this time. Our simple example does not implement this optional behavior.