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


/* 
 * ListEntryUI.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 ListEntryUI extends List implements CommandListener{ 
    private Controller controller; 
    //private Entry[] entries; 
    private Index[] index; 
     
    private Command exit = new Command("返回", Command.BACK, 0); 
    private Command edit = new Command("编辑", Command.ITEM, 1); 
    //private Command add  = new Command("添加",  Command.ITEM, 2); 
    private Command remove = new Command("删除", Command.ITEM, 3); 
    private Command search = new Command("查找",Command.ITEM, 4); 
     
    /** Creates a new instance of ListEntryUI */ 
    public ListEntryUI(Controller controller) { 
        super("联系人列表",List.IMPLICIT); 
        this.controller = controller; 
        addCommand(exit); 
        addCommand(edit); 
        //addCommand(add); 
        addCommand(remove); 
        addCommand(search); 
        setCommandListener(this); 
    } 
    public void commandAction(Command cmd, Displayable d){ 
        if(cmd == exit){ 
            controller.handleCommand(controller.SHOW_LIST_BACK, null); 
        } 
       // if(cmd == add){ 
        //    controller.handleCommand(controller.SHOW_ADD_ENTRY,null); 
       // } 
        if(cmd == search){ 
            controller.handleCommand(controller.SHOW_SEARCH_ENTRY,null); 
        } 
        int index = getSelectedIndex(); 
        if(cmd == edit){ 
              
            controller.handleCommand(controller.SHOW_EDIT_ENTRY, new Object[] {getString(getSelectedIndex())}); 
        } 
        if(cmd == remove){ 
            controller.handleCommand(controller.DO_DELETE_ENTRY, new Object[] {getString(getSelectedIndex())}); 
        } 
        if(cmd ==List.SELECT_COMMAND){ 
             controller.handleCommand(controller.SHOW_DETALL_ENTRY,new Object[] {getString(getSelectedIndex())}); 
        }         
    } 
     
    public void load(Index[] index){ 
         
        if(size()>0){ 
            deleteAll(); 
        }         
        this.index = index;        
        for(int i = 0;i