import javax.microedition.midlet.*; import javax.microedition.lcdui.*; /** * Class Hello - A simple Hello World MIDlet * * @author Ian Utting * @version 1.0 */ public class Hello extends MIDlet implements CommandListener { private Form screen; /** * Called by the Application Management Software (AMS) when the MIDlet * begins execution. The AMS is the software on a device that manages * the downloading and life-cycle of MIDlets. When this constructor * returns, the AMS places the MIDlet in the Paused state. */ public Hello() { screen = new Form("Hello Midlet"); screen.append("Hello small world!"); screen.addCommand(new Command("Exit", Command.EXIT, 0)); screen.setCommandListener(this); } /** * Called by the AMS to shift the MIDlet to the Active state from * the Paused state. While the MIDlet is Active, the AMS can suspend * its execution by calling pauseApp(). */ public void startApp() { Display.getDisplay(this).setCurrent(screen); } /** * Called by the AMS to shift the MIDlet to the Paused state from * the Active state. While the MIDlet is Paused, the AMS can resume * its execution by calling startApp(). * The AMS may shift the MIDlet from Paused to Active or back any * number of times during its execution. */ public void pauseApp() { // Release shared resources allocated in startApp(). } /** * Called by the AMS to terminate execution of the MIDlet. * When this method returns, the MIDlet enters the Destroyed * state. * * @param unconditional Whether to destroy the MIDlet. If true the * MIDlet will enter the Destroyed state regardless * of how this method terminates. If false the MIDlet * may throw a MIDletStateChangeException to request * that it not be destroyed at this time. */ public void destroyApp(boolean unconditional) { // Release resources acquired in the constructor. } /** * Called when a Command is invoked by the user. * In this case, just exit the MIDlet, if it was our Exit command which * was the cause. * @param c The Command which caused this action. * @param d The screen which was being displayed at the time. */ public void commandAction(Command c, Displayable d) { // If it's our exitCommand, destroy ourselves if(c.getLabel().equals("Exit")) { notifyDestroyed(); } } }