PhoneList.java
上传用户:heyongping
上传日期:2022-07-01
资源大小:95k
文件大小:4k
- /*
- * 创建于 2009-12-04
- * 实现罗列所有的电话信息
- */
- package net.garrey.view;
- import java.util.Vector;
- import javax.microedition.lcdui.Command;
- import javax.microedition.lcdui.CommandListener;
- import javax.microedition.lcdui.Displayable;
- import javax.microedition.lcdui.Image;
- import javax.microedition.lcdui.List;
- import net.garrey.model.PhoneItem;
- import net.garrey.util.UIController;
- /**
- * 作者: 张三
- * 默认列出所有信息并实现对 相关操作的监听
- */
- public class PhoneList extends List{
- private UIController controller;
- private Command EXIT_COMMAND;
- private Command ADD_COMMAND;
- private Command EDIT_COMMAND;
- private Command VIEW_COMMAND;
- private Command DELETE_COMMAND;
- private Command ABOUT_COMMAND;
- //添加查找功能
- private Command Find_Command;
-
- private Vector items;
- private Image icon;
- /*
- * 带参数的构造方法,实现操作
- */
- public PhoneList(String title,UIController control,Vector vec){
- super(title,List.IMPLICIT);
- System.out.println("cccccccccccccccccccccc:"+"进入PhoneList");
- //load image
- try{
- icon=Image.createImage("/icon/App.png");
- }catch(java.io.IOException e){
- icon=null;
- System.out.println("load image error");
- }
-
- controller=control;
- this.setCommandListener(new PhoneListListener());
- this.items=vec;
-
- EXIT_COMMAND=new Command("退出",Command.EXIT,1);
- VIEW_COMMAND=new Command("查看",Command.ITEM,2);
- ADD_COMMAND=new Command("添加",Command.ITEM,2);
- EDIT_COMMAND=new Command("编辑",Command.ITEM,2);
- DELETE_COMMAND=new Command("删除",Command.ITEM,2);
- ABOUT_COMMAND=new Command("关于",Command.ITEM,2);
- //添加查找功能
- Find_Command=new Command("查找",Command.ITEM,2);
-
- this.addCommand(EXIT_COMMAND);
- this.addCommand(VIEW_COMMAND);
- this.addCommand(ADD_COMMAND);
- this.addCommand(EDIT_COMMAND);
- this.addCommand(DELETE_COMMAND);
- this.addCommand(ABOUT_COMMAND);
-
- this.addCommand(Find_Command);
-
- if(vec!=null&&vec.size()>0){
- PhoneItem phone=null;
- for(int i=0;i<vec.size();i++){
- phone=(PhoneItem)vec.elementAt(i);
- this.append(phone.getName(),icon);
- }
- }
- }
- /*
- * 实现信息的刷新
- */
- public void refresh(Vector vec){
- this.deleteAll();
- this.items=vec;
- if(vec!=null&&vec.size()>0){
- PhoneItem phone=null;
- for(int i=0;i<vec.size();i++){
- phone=(PhoneItem)vec.elementAt(i);
- this.append(phone.getName(),icon);
- }
- }
- }
- /*
- * 新添加一个记录信息
- */
- public void add(PhoneItem phone){
- this.append(phone.getName(),icon);
- }
-
- //监听器
- private class PhoneListListener implements CommandListener{
- public void commandAction(Command command, Displayable disp){
- if(command==EXIT_COMMAND){
- controller.handleEvent(UIController.EventID.EVENT_EXIT,null);
- }else if(command==VIEW_COMMAND){
- int ind=((List)disp).getSelectedIndex();
- if(ind==-1)
- return;
- Object[] args={items.elementAt(ind)};
- controller.handleEvent(UIController.EventID.EVENT_VIEW_DETAIL,args);
- }else if(command==ADD_COMMAND){
- System.out.println("准备添加一个记录信息");
- controller.handleEvent(UIController.EventID.EVENT_NEW_RECORD,null);
- }else if(command==EDIT_COMMAND){
- int ind=((List)disp).getSelectedIndex();
- if(ind==-1)
- return;
- Object[] args={items.elementAt(ind)};
- controller.handleEvent(UIController.EventID.EVENT_EDIT,args);
- }else if(command==DELETE_COMMAND){
- int ind=((List)disp).getSelectedIndex();
- if(ind==-1)
- return;
- Object[] args={items.elementAt(ind)};
- controller.handleEvent(UIController.EventID.EVENT_DELETE,args);
- }else if(command==ABOUT_COMMAND){
- controller.handleEvent(UIController.EventID.EVENT_ABOUT,null);
- }else if(command==Find_Command){
- controller.handleEvent(UIController.EventID.EVENT_FIND, null);
- }
- }
- }
- }