TextField vs TextBox (1)

23 April 2008

javax.microedition.lcdui provides TextField and TextBox which are sometimes confusing. Both are to allow the user to enter text, but question arises, when to use which one? In this post, I will try to address this issue.

Let me first explain TextFied (javax.microedition.lcdui.TextField). This class inherits from javax.microedition.lcdui.Item, so you should know that its an item that can be placed on a form. To create an instance of TextField, we use the TextField constructor:

TextField(String label, String text, int maxSize, int constraints)

The parameters are self explanatory. Let me present an example:

... 
Display display; 
Form form; 
TextField textField; 
... 
protected void startApp() throws MIDletStateChangeException { 
System.out.println("startApp."); 
display = Display.getDisplay(this); 
form = new Form("Helloworld example"); 
StringItem body = new StringItem(null,"Hello World!"); 
textField = new TextField("Name", "your last name", 15, 0); 
form.append(body); 	    	
form.append(textField);
display.setCurrent(form);

Output:
TextBox

So use Textfield when you want to take input from the user and want to place the field on a form.

In the next post, I will take about TextBox. Do follow that.

del.icio.us:TextField vs TextBox (1)  digg:TextField vs TextBox (1)  spurl:TextField vs TextBox (1)  wists:TextField vs TextBox (1)  simpy:TextField vs TextBox (1)  newsvine:TextField vs TextBox (1)  blinklist:TextField vs TextBox (1)  furl:TextField vs TextBox (1)  reddit:TextField vs TextBox (1)  fark:TextField vs TextBox (1)  blogmarks:TextField vs TextBox (1)  Y!:TextField vs TextBox (1)  smarking:TextField vs TextBox (1)  magnolia:TextField vs TextBox (1)  segnalo:TextField vs TextBox (1)  gifttagging:TextField vs TextBox (1)

Top Of Page | Trackback

If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.

It will look like this: TextField vs TextBox (1)

Leave a Reply