PhoneEdit.java
上传用户:heyongping
上传日期:2022-07-01
资源大小:95k
文件大小:2k
- /*
- * 创建于 2009-12-04
- * 实现对电话号码的编辑
- */
- package net.garrey.view;
- import javax.microedition.lcdui.Command;
- import javax.microedition.lcdui.CommandListener;
- import javax.microedition.lcdui.Displayable;
- import javax.microedition.lcdui.Form;
- import javax.microedition.lcdui.TextField;
- import net.garrey.model.PhoneItem;
- import net.garrey.util.UIController;
- /**
- * 作者: 张三
- * 编辑电话号码信息,实现对编辑保存按钮的监听
- */
- public class PhoneEdit extends Form{
- private UIController controller;
- private Command BACK_COMMAND;
- private Command SAVE_COMMAND;
- private TextField nameField;
- private TextField phoneField;
- private PhoneItem item;
- /*
- * 带参数的构造方法
- */
- public PhoneEdit(String title,UIController control){
- super(title);
- controller=control;
- this.setCommandListener(new PhoneEditListener());
-
- BACK_COMMAND=new Command("返回",Command.BACK,1);
- SAVE_COMMAND=new Command("保存",Command.OK,2);
- this.addCommand(BACK_COMMAND);
- this.addCommand(SAVE_COMMAND);
-
- nameField=new TextField("名字","",15,TextField.ANY);
- phoneField=new TextField("电话","",15,TextField.PHONENUMBER);
- this.append(nameField);
- this.append(phoneField);
- }
- /*
- * 重新修改内容信息
- */
- public void setPhone(PhoneItem item){
- this.item=item;
- nameField.setString(item.getName());
- phoneField.setString(item.getPhonenum());
- }
- //监听器
- private class PhoneEditListener implements CommandListener{
- public void commandAction(Command command, Displayable disp){
- if(command==BACK_COMMAND){
- controller.handleEvent(UIController.EventID.EVENT_EDIT_BACK,null);
- }else if(command==SAVE_COMMAND){
- String name=nameField.getString();
- String phone=phoneField.getString();
- if((name==null||name.equals(""))||(phone==null||phone.equals(""))){
- return;
- }
-
- item.setName(name);
- item.setPhonenum(phone);
- Object[] args={item};
- controller.handleEvent(UIController.EventID.EVENT_EDIT_SAVE,args);
- }//end else
- }
- }//end inner class
-
- }