Mega Code Archive

 
Categories / Java / J2ME
 

Phone Book

/*  * PhoneBook.java   * Copyright (c) 2000 Sun Microsystems, Inc. All Rights Reserved.  *  * This software is the confidential and proprietary information of Sun  * Microsystems, Inc. ("Confidential Information").  You shall not  * disclose such Confidential Information and shall use it only in  * accordance with the terms of the license agreement you entered into  * with Sun.  *  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING  * THIS SOFTWARE OR ITS DERIVATIVES.  */ 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(" ");     }   } }