ch.aplu.gidlet
Class MForm

java.lang.Object
  extended by javax.microedition.lcdui.Displayable
      extended by javax.microedition.lcdui.Screen
          extended by javax.microedition.lcdui.Form
              extended by ch.aplu.gidlet.MForm

public class MForm
extends javax.microedition.lcdui.Form

Form display with simple input and output items. A soft button 'Exit' is shown. Hitting the corresponding key will call the Gidlet's doExit(). If you do not need this button, invoke removeExitButton().
If you implement your own CommandListener and call setCommandListener(), the internal CommandListener is disabled.
main() serves as entry point for the user programm. It is called in the run-method of a separate thread and should terminate to avoid non-terminated threads.
Creation may take place within main() or while declaring instance variable of the application program.
If you register your own ItemStateListener, you will loose the internal one, which is used to verify integer and double values entered with addInputField(). If you want to maintain this feature you must call the MForm.itemStateListener() in your own itemStateListener.
Example:


import ch.aplu.gidlet.*;
import javax.microedition.lcdui.*;

public class SimpleFormGidlet extends Gidlet
{
  private TextField tf1;
  private TextField tf2;
  private StringItem it;

  private MForm form = new MForm("MForm example");

  public void main()
  {
    tf1 = form.addInputField("Your first name:", "");
    tf2 = form.addInputField("Your family name:", "");
    it = form.addOutputField();
    form.addOkButton();
    form.show();
  }

  public void doOk()
  {
    String val1 = form.getText(tf1);
    String val2 = form.getText(tf2);
    it.setText("Hello,\n" + val1 + " " + val2);
  }
}
 


Constructor Summary
MForm()
          Constructs a MForm with no title.
MForm(java.lang.String title)
          Constructs a MForm with given title.
 
Method Summary
 javax.microedition.lcdui.TextField addInputField(java.lang.String prompt, java.lang.String init)
          Adds a input text field to the MForm with given prompt, given initial value with no validation.
 javax.microedition.lcdui.TextField addInputField(java.lang.String prompt, java.lang.String init, int validation)
          Adds a input text field to the MForm with given prompt, given initial value and given validation type.
 void addOkButton()
          Adds an OK soft button with label "OK".
 void addOkButton(java.lang.String label)
          Adds an OK soft button with given label.
 javax.microedition.lcdui.StringItem addOutputField()
          Adds a empty output text field to the MForm.
 java.lang.String getText(javax.microedition.lcdui.Item item)
          Returns current text from the given TextField or StringItem, null if not one of these.
 void itemStateChanged(javax.microedition.lcdui.Item item)
          Calls the internal ItemStateListener which is used to verify integer and double values entered with addInputField().
 void removeExitButton()
          Removes Exit soft button.
 void removeOkButton()
          Removes Ok soft button.
 void setText(javax.microedition.lcdui.Item item, java.lang.String text)
          Writes given text to the given Item (must be a StringItem).
 void setText(javax.microedition.lcdui.StringItem item, java.lang.String text)
          Writes given text to the given StringItem (subclass of Item).
 void show()
          Shows the form display if it is not yet visible or it was previously hidden by another display.
 void show(boolean wait)
          Shows the form display if it is not yet visible or it was previously hidden by another display.
 
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
 

Constructor Detail

MForm

public MForm(java.lang.String title)
Constructs a MForm with given title. The display is initially invisible and should be made visible by calling show().


MForm

public MForm()
Constructs a MForm with no title. The display is initially invisible and should be made visible by calling show().

Method Detail

show

public void show()
Shows the form display if it is not yet visible or it was previously hidden by another display. Because it is not garanteed that the diplay is actually visible when Display.setCurrent() returns, wait for a maximum of 5 s for the display to get shown.


show

public void show(boolean wait)
Shows the form display if it is not yet visible or it was previously hidden by another display. If wait = true, block until the display becomes actually visible, up to a maximum auf 5 seconds. This may be useful to observe the start of an animation.


addInputField

public javax.microedition.lcdui.TextField addInputField(java.lang.String prompt,
                                                        java.lang.String init,
                                                        int validation)
Adds a input text field to the MForm with given prompt, given initial value and given validation type. For validation types consult documentation for class ch.aplu.gidlet.Gidlet.

Returns:
Reference to the created instance of TextField (subclass of Item)
See Also:
Gidlet

addInputField

public javax.microedition.lcdui.TextField addInputField(java.lang.String prompt,
                                                        java.lang.String init)
Adds a input text field to the MForm with given prompt, given initial value with no validation.

Returns:
Reference to the created instance of TextField (subclass of Item)

addOutputField

public javax.microedition.lcdui.StringItem addOutputField()
Adds a empty output text field to the MForm. Text is written in the field with setText(). Nothing is seen until some text is written. If the text exceeds the height if the display, the first line is on the top and the text may be scrolled using a small scroll icon. Lines are separated by the plattform's line separator. If the length of a line exceeds the width of the display, the line wraps at word bounds.
Newline character '\n' is supported to force a line wrap.

Returns:
Reference to the created instance of StringItem (subclass of Item)

getText

public java.lang.String getText(javax.microedition.lcdui.Item item)
Returns current text from the given TextField or StringItem, null if not one of these.


setText

public void setText(javax.microedition.lcdui.StringItem item,
                    java.lang.String text)
Writes given text to the given StringItem (subclass of Item).


setText

public void setText(javax.microedition.lcdui.Item item,
                    java.lang.String text)
Writes given text to the given Item (must be a StringItem). (For backward compatibility only.)


itemStateChanged

public void itemStateChanged(javax.microedition.lcdui.Item item)
Calls the internal ItemStateListener which is used to verify integer and double values entered with addInputField(). If you register your own ItemStateListener and you want to maintain the verification, call this method in your own itemStateChanged().


addOkButton

public void addOkButton()
Adds an OK soft button with label "OK". When pressed, the Gidlet's callback notification doOk() is called unless you register your own CommandListener.


addOkButton

public void addOkButton(java.lang.String label)
Adds an OK soft button with given label. When pressed, the Gidlet's callback notification doOk() is called unless you register your own CommandListener.


removeExitButton

public void removeExitButton()
Removes Exit soft button. Gidlet's callback notification doExit() is disabled.


removeOkButton

public void removeOkButton()
Removes Ok soft button. Gidlet's callback notification doOk() is disabled.