www.pudn.com > phonebk.rar > EditEntryUI.java


/* 
 * EditEntryUI.java 
 * 
 * Created on 2006年3月17日, 上午10:14 
 * 
 * To change this template, choose Tools | Options and locate the template under 
 * the Source Creation and Management node. Right-click the template and choose 
 * Open. You can then make changes to the template in the Source Editor. 
 */ 
 
package com.j2medev.sample.phonebook; 
 
import javax.microedition.lcdui.*; 
/** 
 * 
 * @author Admin 
 */ 
public class EditEntryUI extends Form implements CommandListener{ 
    private Controller controller; 
    private Entry entry; 
    private TextField name = new TextField("姓名", null, 10, TextField.ANY); 
    private TextField mobile = new TextField("手机号", null, 11, TextField.NUMERIC); 
    private TextField phone = new TextField("固定电话", null, 15, TextField.NUMERIC); 
    private TextField email = new TextField("电子邮件", null, 20, TextField.ANY); 
    private TextField address = new TextField("住址",null, 20, TextField.ANY); 
    private TextField qq = new TextField("QQ号", null, 15, TextField.NUMERIC); 
     
    private Command ok = new Command("确定", Command.OK, 0); 
    private Command cancel = new Command("取消", Command.CANCEL, 0); 
    private String oldname = null; 
     
     
    /** Creates a new instance of EditEntryUI */ 
    public EditEntryUI(Controller controller) { 
        super("更改联系人信息"); 
        this.controller = controller; 
        append(name); 
        append(mobile); 
        append(phone); 
        append(email); 
        append(address); 
        append(qq); 
        addCommand(ok); 
        addCommand(cancel); 
        setCommandListener(this); 
         
    } 
    public void commandAction(Command cmd, Displayable d){ 
        if(cmd == ok){ 
            entry.setName(name.getString()); 
            entry.setMobile(mobile.getString()); 
            entry.setPhone(phone.getString()); 
            entry.setEmail(email.getString()); 
            entry.setAddress(address.getString()); 
            entry.setQQ(qq.getString()); 
            controller.handleCommand(controller.DO_UPDATE_ENTRY, new Object[] {oldname,entry}); 
             
        } 
        if(cmd == cancel){ 
            controller.handleCommand(controller.SHOW_LIST_ENTRY, null); 
        } 
    } 
    public void load(Entry entry){ 
        this.entry = entry; 
        name.setString(entry.getName()); 
        mobile.setString(entry.getMobile()); 
        phone.setString(entry.getPhone()); 
        email.setString(entry.getEmail()); 
        address.setString(entry.getAddress()); 
        qq.setString(entry.getQQ()); 
         
        oldname = name.getString(); 
    } 
     
}