Home J2me Phone Book Midlet Example
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Phone Book Midlet Example

Advertisement
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

Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 3, 2008

Ask Questions?    Discuss: Phone Book Midlet Example   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Debasree
June 2, 2011
problem with this (PhoneBook) example

hi, I m learning J2ME. I used this given program. The program build properly, but when i run this program, the emulator appears and vanishes after few seconds. and before that no action was accepted. I can not get the problem. please help asap.
Noll
November 18, 2011
easy2learn

through this easy 2 learn any difficult task. so thanks & keep it up.
watuwa simon
April 10, 2012
more

i would you to show me how to develop mobile application
DMCA.com