文件名称:java写的代码手机功能简单的
文件大小:3KB
文件格式:JAVA
更新时间:2014-06-24 14:01:59
phoneadd
import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.Image; import javax.microedition.lcdui.ImageItem; import javax.microedition.lcdui.Item; import javax.microedition.lcdui.TextField; public class PhoneAdd extends Form { private UIController controller; private Command BACK_COMMAND; private Command SAVE_COMMAND; private TextField nameField; private TextField phoneField; private TextField QQField; private TextField sexField; private TextField ageField; // private ImageItem iconQQ; // private Image icon; public PhoneAdd(String title, UIController control) { super(title); controller = control; this.setCommandListener(new PhoneAddListener()); BACK_COMMAND = new Command("返回", Command.BACK, 1); SAVE_COMMAND = new Command("确认", Command.OK, 2); this.addCommand(BACK_COMMAND); this.addCommand(SAVE_COMMAND); /* try{ icon=Image.createImage("/icon/7.png"); }catch(java.io.IOException e){ icon=null; System.out.println("图片导入异常"); } */ nameField = new TextField("名字", "", 16, TextField.ANY); phoneField = new TextField("电话", "", 16, TextField.PHONENUMBER); QQField = new TextField("QQ", "", 11, TextField.NUMERIC); sexField = new TextField("性别", "", 2, TextField.ANY); ageField = new TextField("年龄","",3,TextField.NUMERIC); // iconQQ=new ImageItem("",icon,Item.LAYOUT_LEFT,"图片无法显示"); this.append(nameField); this.append(phoneField); this.append(sexField); // this.append(iconQQ); this.append(QQField); this.append(ageField); } public void clear() { nameField.setString(""); phoneField.setString(""); sexField.setString(""); QQField.setString(""); ageField.setString(""); } private class PhoneAddListener implements CommandListener { public void commandAction(Command command, Displayable disp) { if (command == BACK_COMMAND) { controller.handleEvent(UIController.EventID.EVENT_VIEW_BACK, null); } else if (command == SAVE_COMMAND) { String name = nameField.getString(); String phone = phoneField.getString(); String QQ = QQField.getString(); String sex = sexField.getString(); String age= ageField.getString(); if ((name == null || name.equals("")) || (phone == null || phone.equals(""))) { return; } Object[] args = { name, phone, QQ, sex ,age}; controller.handleEvent(UIController.EventID.EVENT_NEW_SAVE, args); } } } }