Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Text Field Midlet Example 
 

This example illustrates how to insert text field in your form. We are using here two TextField (name and company). We are taking both TextField variable in to the constructor (TextFieldExample) of the class.

 

Text Field MIDlet Example

                         

This example illustrates how to insert text field in your form. We are using here two TextField (name and company). We are taking both TextField variable in to the constructor (TextFieldExample) of the class. When application will be run then first of all the startApp() method will called and it display the form with name and company field. The TextField is in the javax.microedition.lcdui package, has the following methods:

  • delete(int offset, int length) 
  • getCaretPosition() 
  • getChars(char[] data)
  • getConstraints()
  • getMaxSize() 
  • getString()
  • insert(char[] data, int offset, int length, int position) 
  • insert(String src, int position)
  • setChars(char[] data, int offset, int length) 
  • setConstraints(int constraints) 
  • setMaxSize(int maxSize) 
  • setString(String text) 
  • size() 

Application display as follows:

 

 

Source code of TextFieldExample.java is as follows:

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class TextFieldExample extends MIDlet implements CommandListener{
  private Form form;
  private Display display;
  private TextField name, company;
  private Command ok;
  
  public TextFieldExample(){
    name = new TextField("Name:"""30, TextField.ANY);
    company = new TextField("Company Name:"""30, TextField.ANY);
    ok = new Command("OK", Command.OK, 2);
  }

  public void startApp(){
    display = Display.getDisplay(this);
    Form form = new Form("Text Field");
    form.append(name);
    form.append(company);
    form.addCommand(ok);
    form.setCommandListener(this);
    display.setCurrent(form);
  }

  public void pauseApp(){
  
  }

  public void destroyApp(boolean destroy){
    notifyDestroyed();
  }

  public void showInput(){
    display = Display.getDisplay(this);
    String n = name.getString();
    String c = company.getString();
    Form form = new Form("Input Value");
    form.append(n);
    form.append(c);
    display.setCurrent(form);
  }


  public void commandAction(Command c, Displayable d) {
    String label = c.getLabel();
    if(label.equals("OK")){
      showInput();
    
  }
}

 

Download Source Code

                         

» View all related tutorials
Related Tags: c j2me diff types type if example to rectangle draw exam raw angle e il pe in different m nt

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

Text Field Midlet Example


This example illustrates how to insert text field in your form. We are using here two TextField (name and company). We are taking both TextField variable in to the constructor (TextFieldExample) of the class. When application will be run then first of all the startApp() method will called and it display the form with name and company field. The TextField is in the javax.microedition.lcdui package, has the following methods:

delete(int offset, int length)
getCaretPosition()
getChars(char[] data)
getConstraints()
getMaxSize()
getString()
insert(char[] data, int offset, int length, int position)
insert(String src, int position)
setChars(char[] data, int offset, int length)
setConstraints(int constraints)
setMaxSize(int maxSize)
setString(String text)
size()
Application display as follows:











Source code of TextFieldExample.java is as follows:

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class TextFieldExample extends MIDlet implements CommandListener{
private Form form;
private Display display;
private TextField name, company;
private Command ok;

public TextFieldExample(){
name = new TextField("Name:", "", 30, TextField.ANY);
company = new TextField("Company Name:", "", 30, TextField.ANY);
ok = new Command("OK", Command.OK, 2);
}

public void startApp(){
display = Display.getDisplay(this);
Form form = new Form("Text Field");
form.append(name);
form.append(company);
form.addCommand(ok);
form.setCommandListener(this);
display.setCurrent(form);
}

public void pauseApp(){

}

public void destroyApp(boolean destroy){
notifyDestroyed();
}

public void showInput(){
display = Display.getDisplay(this);
String n = name.getString();
String c = company.getString();
Form form = new Form("Input Value");
form.append(n);
form.append(c);
display.setCurrent(form);
}


public void commandAction(Command c, Displayable d) {
String label = c.getLabel();
if(label.equals("OK")){
showInput();
}
}
}

Posted by aditya on Saturday, 10.11.08 @ 11:38am | #81010

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.