Enter data, view it back and using List in J2ME

Hello friends, todays’ story is; first you enter your name in a form, then after you click on a command you will be able to see your name with another message, after that you will be provided selection list to choose. 😦 I know you are confused about what I am talking. Don’t worry just see below images to get an idea about our next mobile application.

First Two ViewsToday you will be able to identify below classes;

  • List
  • String
  • TextBox

Last Two Interfaces

Lets see the code which create above interfaces and the functions.

package anuja;

import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;

 * @author Anuja
public class SelectYourChoice extends MIDlet implements CommandListener {
    private Display display;
    private Form selectForm;
    private TextField nameTxtFld;
    private List choiceList;
    private Command exitCmd;
    private Command nextCmd;
    private TextBox nameTxtBox;
    private String yourName;
    private Command goCmd;

    public void startApp() {
        display = Display.getDisplay(this);
        selectForm = new Form("Select Your Choice");
        nameTxtFld = new TextField("Enter Your Name", "", 30, TextField.ANY);

        exitCmd = new Command("Exit", Command.EXIT, 7);
        nextCmd = new Command("Ok", Command.OK, 4);


        choiceList = new List("Select a language", Choice.MULTIPLE);
        choiceList.append("Java", null);
        choiceList.append("C++", null);
        choiceList.append("PHP", null);


        nameTxtBox = new TextBox("Welcome", "", 300, TextField.ANY);
        goCmd = new Command("Go", Command.OK, 4);



    public void pauseApp() {

    public void destroyApp(boolean unconditional) {

    public void commandAction(Command c, Displayable d) {
        if(c == exitCmd){
        }else if(c == nextCmd){
            yourName = nameTxtFld.getString();
            nameTxtBox.setString("Hi " + yourName + "\n Choose your favorite programming language next");
        }else if(c == goCmd){

The things you have to remember is, you can’t append a List in to Form. Another thing that I got stuck is we can’t append Form components like TextField cannot append to a List also. But we can add Commands to a List as I have done. Lets see the reasons for those in a future post. Thanks for reading 🙂

About AnujAroshA

Working as an Associate Technical Lead. Specialized in iOS application development. A simple person :)
This entry was posted in J2ME examples. Bookmark the permalink.

1 Response to Enter data, view it back and using List in J2ME

  1. Rahul Kumar says:

    sir I use the both the component in the screen Text Field and Text Box, but it con not add Form Plz tell me What to do in this situation. Generally I see in the Mobile phone in the Message used the both Text Field and Text Box but I and use it Plz give me suitable Example to this design.

    and another query is to send the one Component fully as the Gallery,Message Box,setting and Phone Book any one.
    My Email Id is:chauhans13@gmail.com,rahulchauhan.mca1@gmail.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s