com.nokia.midp.examples.lcdui.helloworldplus
Class TextEditor

java.lang.Object
  extended byjavax.microedition.lcdui.Displayable
      extended byjavax.microedition.lcdui.Screen
          extended byjavax.microedition.lcdui.Form
              extended bycom.nokia.midp.examples.lcdui.helloworldplus.TextEditor
All Implemented Interfaces:
javax.microedition.lcdui.CommandListener

public class TextEditor
extends javax.microedition.lcdui.Form
implements javax.microedition.lcdui.CommandListener

The TextEditor class allows the user to edit the message displayed.

This class extends the Form class and uses an instance of TextField to provide an editable text field.

The initial text message can set via the constructor or via setText() method.


Field Summary
private static javax.microedition.lcdui.Command CMD_CANCEL
          Command specified to dismiss the TextEditor form and reject the edited text.
private static javax.microedition.lcdui.Command CMD_OK
          Command specified to dismiss the TextEditor form and accept the edited text.
private static int COMMAND_PRIORITY
          Priority of commands relative to others of the same type.
private static int MAX_TEXT_SIZE
          The maximum size of the text allowed in the text field.
private  HelloWorldPlusMIDlet midlet
          Back reference to parent MIDlet class enabling this class to access to access the callback methods provided by HelloWorldMIDlet.
private  javax.microedition.lcdui.TextField textField
          Reference to the instance of the TextField class created and appended to the form.
 
Fields inherited from class javax.microedition.lcdui.Form
 
Fields inherited from class javax.microedition.lcdui.Displayable
 
Constructor Summary
(package private) TextEditor(HelloWorldPlusMIDlet midlet, java.lang.String message)
          The constructor initializes the class making it ready for use.
 
Method Summary
 void commandAction(javax.microedition.lcdui.Command cmd, javax.microedition.lcdui.Displayable source)
          Handles commands received.
 void setText(java.lang.String message)
          Sets the opening text in the textfield.
 
Methods inherited from class javax.microedition.lcdui.Form
append, append, append, delete, deleteAll, get, getHeight, getWidth, insert, set, setItemStateListener, size
 
Methods inherited from class javax.microedition.lcdui.Displayable
addCommand, getTicker, getTitle, isShown, removeCommand, setCommandListener, setTicker, setTitle, sizeChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

textField

private javax.microedition.lcdui.TextField textField
Reference to the instance of the TextField class created and appended to the form.


midlet

private final HelloWorldPlusMIDlet midlet
Back reference to parent MIDlet class enabling this class to access to access the callback methods provided by HelloWorldMIDlet.


COMMAND_PRIORITY

private static final int COMMAND_PRIORITY
Priority of commands relative to others of the same type.

See Also:
Constant Field Values

CMD_OK

private static final javax.microedition.lcdui.Command CMD_OK
Command specified to dismiss the TextEditor form and accept the edited text.


CMD_CANCEL

private static final javax.microedition.lcdui.Command CMD_CANCEL
Command specified to dismiss the TextEditor form and reject the edited text.


MAX_TEXT_SIZE

private static final int MAX_TEXT_SIZE
The maximum size of the text allowed in the text field.

See Also:
Constant Field Values
Constructor Detail

TextEditor

TextEditor(HelloWorldPlusMIDlet midlet,
           java.lang.String message)
The constructor initializes the class making it ready for use.

It initializes the reference to the parent MIDlet class with the paramater value 'midlet'.
It creates an instance of TextField initialized with the parameter 'message'.
It appends the created instance of TextField to the form.
It adds the Command objects defined to the command handling framework.
It calls setCommandListener() to register itself with the command framework as the command listener and will be notified when a command is activated.

Parameters:
midlet - is a reference to the parent MIDlet. Enables callback to parent object.
message - sets the opening text in the text field.
Method Detail

commandAction

public void commandAction(javax.microedition.lcdui.Command cmd,
                          javax.microedition.lcdui.Displayable source)
Handles commands received.

The CMD_OK command instructs the MIDlet to dismiss the form and accept the edited text. The method handles this command by calling the parent method textEditorDone() passing an initialised instance of String.

The CMD_CANCEL command instructs the MIDlet to dismiss the form and reject the edited text. The method handles this command by calling the parent method textEditorDone() passing an uninitialised reference.

Specified by:
commandAction in interface javax.microedition.lcdui.CommandListener
Parameters:
cmd - is the identity of command received from the framework.
source - is the identity of the UI area displayed which generated the command.

setText

public void setText(java.lang.String message)
Sets the opening text in the textfield.

Parameters:
message - is the opening text to be displayed