⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 listphoneui.java

📁 基于j2me的电话本基于j2me的电话本
💻 JAVA
字号:
package com.hziee.phone_book.ui;

import javax.microedition.lcdui.*;
import com.hziee.phone_book.model.*;

public class ListPhoneUI extends List implements CommandListener
{
    private UIController uicontroller;
    //private int listNum = 0;
    //private int lastSize = 0;

    public static final Command modifyCommand = new Command("编辑",Command.OK,3);
    public static final Command backCommand = new Command("返回", Command.BACK, 2);
    public static final Command infoCommand = new Command("详情", Command.ITEM, 1);
    public static final Command deleCommand = new Command("删除", Command.OK, 3);

    public ListPhoneUI(UIController uicontroller)
    {
        super(Title.listPhoneTitle, List.IMPLICIT);//简易类型的List
        this.uicontroller = uicontroller;
        this.addCommand(modifyCommand);
        this.addCommand(backCommand);
        this.addCommand(deleCommand);
        this.addCommand(infoCommand);
        this.setCommandListener(this);
    }

    public void init(Index[] index)
    {
        /*
        for (int i = lastSize-1; i >= 0; i--)
        {
            delete(i);
        }
        */
        deleteAll();//清除菜单。。
        //获得每以条索引
        for (int i = 0; i < index.length; i++)
        {
            append(index[i].getKey(), null);
        }
        //lastSize = index.length;

    }
    
    public void deleteAll()
    {
        int size = size();
        //从最后一条记录开始删除
        for(int i = size-1;i>=0;i--)
        {
            delete(i);
        }
    }
    /*
    public void subLastSize()
    {
        lastSize--;
    }
    */
 public void commandAction(Command arg0, Displayable arg1)
    {
        // TODO Auto-generated method stub
        if (arg0 == backCommand)
        {
            uicontroller
                    .handleEvent(UIController.EventID.EVENT_LISTPHONE_BACK_WELCOME);

        } else if (arg0 == deleCommand)
        {
            if(size()==0)
            {
                uicontroller.showAlert("无效操作!",this,AlertType.WARNING);
                return;
            }
            String record = getString(getSelectedIndex());
            int index = getSelectedIndex();
            uicontroller.handleEvent(UIController.EventID.EVENT_DELETE_RECORD,
                    new Object[] { record, new Integer(index) });
        } else if (arg0 == infoCommand)
        {
            if(size()==0)
            {
                uicontroller.showAlert("无效操作!",this,AlertType.WARNING);
                return;
            }
            String record = getString(getSelectedIndex());
            uicontroller.handleEvent(
                    UIController.EventID.EVENT_DISPLAY_INFOMATION,
                    new Object[] { record });
        }else if (arg0 == modifyCommand)
        {
        	if(size()==0)
        	{
        		uicontroller.showAlert("无效操作!", this, AlertType.WARNING);
        		return;
        	}
        	String record = getString(getSelectedIndex());
        	uicontroller.handleEvent(UIController.EventID.EVENT_MODIFY_RECORD, new Object[] { record });
        	}

    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -