001
002 package com.nokia.midp.examples.lcdui.helloworldplus;
003
004 import javax.microedition.midlet.*;
005 import javax.microedition.lcdui.*;
006
007 /**
008 * This class illustrates the implementation of a simple MIDlet that initially
009 * displays a "HelloWorld" message to the screen and allows the user to edit
010 * that message.
011 * <p>
012 * This class extends the class javax.microedition.midlet.MIDlet. It
013 * creates and maintains references to a TextScreen object and a
014 * TextEditor object.
015 * <p>
016 * Note that the HelloWorldMIDlet class has no constructor. MIDlet
017 * contructors are not required to do anything because intializing of the
018 * object is better performed in the startApp() method.
019 */
020 public class HelloWorldPlusMIDlet extends MIDlet {
021
022 /** Displays the message on the screen. */
023 private TextScreen textScreen;
024
025 /** Allows the user to edit the message displayed. */
026 private TextEditor textEditor;
027
028 /** A generic way of indicating whether startApp() has previously been called. */
029 private Display display;
030
031 /**
032 * Creates an instance of TextScreen if one has not already been
033 * created and tells the framework to set this instance of TextScreen
034 * as the current screen.
035 */
036 public void startApp() {
037 if (display == null) {
038 // First time we've been called.
039 display=Display.getDisplay(this);
040 textScreen = new TextScreen(this, "Hello World!");
041 }
042 display.setCurrent(textScreen);
043 }
044
045 /**
046 * This must be defined but no implementation is required because the MIDlet
047 * only responds to user interaction.
048 */
049 public void pauseApp() {
050 }
051
052 /**
053 * No further implementation is required because the MIDlet holds no
054 * resources that require releasing.
055 *
056 * @param unconditional is ignored.
057 */
058 public void destroyApp(boolean unconditional) {
059 }
060
061 /**
062 * A convenience method for exiting.
063 */
064 public void exitRequested(){
065 destroyApp(false);
066
067 /*
068 * notifyDestroyed() tells the scheduler that this MIDlet is now in a
069 * destroyed state and is ready for disposal.
070 */
071 notifyDestroyed();
072 }
073
074 /**
075 * Implements the transition from the TextEditor screen to the TextScreen screen.
076 *
077 * @param string is the new text to be displayed. It is null if the text is
078 * not to be changed.
079 */
080 public void textEditorDone(String string) {
081 if (string != null) {
082 textScreen.setCurrentText(string);
083 }
084 display.setCurrent(textScreen);
085 }
086
087 /**
088 * Implements the transition from the TextScreen screen to the TextEditor screen.
089 */
090 public void textEditorRequested() {
091 String currentText = textScreen.getCurrentText();
092 if (textEditor == null) {
093 textEditor = new TextEditor(this, currentText);
094 } else {
095 textEditor.setText(currentText);
096 }
097 display.setCurrent(textEditor);
098 }
099 }