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

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Phone Book Midlet Example 
 

This example illustrates how to create your phone book. In this example we are taking three SCREEN button ("Next", "New", "Exit") and taking two TextBox ("name", "number").

 

J2ME Contact List

                         

This Example goes to create a Phone Book MIDlet

This example illustrates how to create your phone book. In this example we are taking three SCREEN button ("Next", "New", "Exit") and taking two TextBox ("name", "number"). In the name field user enters name and in number field user enters phone number. When user enters name and click on Next button then number text box will open, now user enters phone number. In case user select  "Exit" or  "New" the name and number get prints on the console. 

When program will run initially, startApp() method will be called. And both "Enter Name" text box and the "Next" button will be displayed. After that if user clicks on next button the commandAction() method will be called that will check, if label is equal to "Next" then number TextBox will appear on the screen that can be used to enter the phone number of user. 

 

The application display as below:

 

 

 

Source code of PhoneBookExample.java

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

public class PhoneBookExample extends MIDlet implements CommandListener {
  private Command exit, next, New;
  private TextBox name, number;
  private Display display;
  private String nam, no;
  private Form form;
  
  public PhoneBookExample(){
    next = new Command("Next", Command.SCREEN, 2);
    exit = new Command("Exit", Command.SCREEN, 2);
    New = new Command("New", Command.SCREEN, 2);
  }

  public void startApp(){
    display = Display.getDisplay(this);
    name = new TextBox("Enter Name"""30, TextField.ANY);
    name.addCommand(next);
    name.setCommandListener(this);
    number = new TextBox("Enter Number"""13, TextField.PHONENUMBER);
    number.addCommand(New);
    number.addCommand(exit);
    number.setCommandListener(this);
    display.setCurrent(name);
  }

  public void pauseApp() {}

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

  public void commandAction(Command c, Displayable s){
    String label = c.getLabel();
    if (label.equals("Exit")){
      nam = name.getString();
      no = number.getString();
      System.out.println("Name = " + name.getString() ", 
      Number = "
+ number.getString());
      destroyApp(false);
    else if (label.equals("Next")){
      number.setString("");
      display.setCurrent(number);
    else if (label.equals("New")){
      display.setCurrent(name);
      nam = name.getString();
      no = number.getString();
      System.out.println("Name = " + name.getString() ", 
      Number = "
+ number.getString());
      name.setString("");
    }
  }
}

 

Download Source Code

                         

» View all related tutorials
Related Tags: c io vi lock this block set frame example ram exam locks e il manual blocks man in as m

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 
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.