JAVA SOURCE CODE

J2ME PHONE BOOK APPLICATION

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


public class PhoneBook extends MIDlet implements CommandListener {

private Command exitCommand; // The exit command

private Command nextCommand;

private Command newCommand;

private TextBox t1;

private TextBox t;

private Display display; // The display for this MIDlet

private String _name;

private String _number;

public PhoneBook() {
display = Display.getDisplay(this);
nextCommand = new Command("Next", Command.SCREEN, 2);
exitCommand = new Command("Exit", Command.SCREEN, 2);
newCommand = new Command("NewNumber", Command.SCREEN, 2);

}

public void startApp() {
t = new TextBox("Name", "", 256, TextField.ANY);
t.addCommand(nextCommand);
t.setCommandListener(this);

t1 = new TextBox("Number", "", 256, TextField.PHONENUMBER);
t1.addCommand(newCommand);
t1.addCommand(exitCommand);
t1.setCommandListener(this);

display.setCurrent(t);

}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}

public void commandAction(Command c, Displayable s) {
if (c == exitCommand) {
_name = t.getString();
_number = t1.getString();
System.out.println("Name = " + t.getString() + ", Number = "
+ t1.getString());
destroyApp(false);
notifyDestroyed();
}
if (c == nextCommand) {
t1.setString(" ");
display.setCurrent(t1);
}
if (c == newCommand) {
display.setCurrent(t);
_name = t.getString();
_number = t1.getString();
System.out.println("Name = " + t.getString() + ", Number = "
+ t1.getString());
t.setString(" ");
}

}

}

No comments:

Post a Comment