//HelloWorldMIDlet.java
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class HelloWorldMIDlet extends MIDlet implements CommandListener
{
  // Initialize the Midlet Display variable
  private Display MIDletDisplay;

  // Initialize a variable for the cmdExit 
  private Command cmdExit;

  public HelloWorldMIDlet()
  { 
    // Retrieve the display from the static display object
    midletDisplay = Display.getDisplay(this);

	// Initialize the cmdExit
    cmdExit = new Command("Exit", Command.SCREEN, 1);
  } 
 
  public void startApp()
  { 
    // Create the TextBox containing the "Hello,World!" message
    TextBox textBox = new TextBox("Hello Midlet", "Hello,World!!", 256, 0);

    // Add the Exit Command to the TextBox
    textBox.addCommand(cmdExit);

    // Set the command listener for the textbox to the current MIDlet
    textBox.setCommandListener((CommandListener)this);

    // Set the current display of the MIDlet to the textBox screen
    midletDisplay.setCurrent(textBox);
  } 

  /*
  * PauseApp is used to suspend background activities and release 
  * resources on the device when the MIDlet is not active. 
  */ 
  public void pauseApp()
  { 
  } 

  /*
  * DestroyApp is used to stop background activities and release 
  * resources on the device when the MIDlet is at the end of its 
  * life cycle. 
  */ 
  public void destroyApp(boolean unconditional)
  {
  } 

  /* 
  * The commandAction method is implemented by this MIDlet to 
  * satisfy the CommandListener interface and handle the Exit action. 
  */ 
  public void commandAction(Command command, Displayable screen) 
  { 
    // If the command is the cmdExit
    if(command==cmdExit)
    { 
      // Call the destroyApp method 
      destroyApp(false);

      // Notify the MIDlet platform that the MIDlet has completed 
      notifyDestroyed(); 
    }
  }
}


