• Java Me-List控件的用法案例


    /**
    * Java Me-List控件的用法案例
    */
    package com.xushouwei.cn;

    import java.io.IOException;
    import javax.microedition.lcdui.Choice;
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Image;
    import javax.microedition.lcdui.List;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    public class ListDemo extends MIDlet implements CommandListener{
    //定义两种事件类型
    private final static Command CMD_EXIT=new Command("Exit",Command.EXIT,1);
    private final static Command CMD_BACK=new Command("Back", Command.BACK, 1);
    //定义Display对象
    private Display display;
    private List mainList;
    private List execlusiveList;
    private List implicitList;
    private List multipleList;
    private boolean firstTime;
    public ListDemo()
    {
    display=Display.getDisplay(this);
    String[] stringArray={"Option A","Option B","Option C","Option D"};
    Image[] imageArray=null;
    execlusiveList=new List("Exclusive",Choice.EXCLUSIVE,stringArray, imageArray);
    execlusiveList.addCommand(CMD_BACK);
    execlusiveList.addCommand(CMD_EXIT);
    execlusiveList.setCommandListener(this);

    implicitList=new List("Implicit",Choice.IMPLICIT,stringArray, imageArray);
    implicitList.addCommand(CMD_BACK);
    implicitList.addCommand(CMD_EXIT);
    implicitList.setCommandListener(this);

    multipleList=new List("Multiple",Choice.MULTIPLE,stringArray, imageArray);
    multipleList.addCommand(CMD_BACK);
    multipleList.addCommand(CMD_EXIT);
    multipleList.setCommandListener(this);

    firstTime=true;
    }

    public void commandAction(Command c, Displayable d) {
    // TODO Auto-generated method stub
    if (d.equals(mainList)) {
    if(c==List.SELECT_COMMAND)
    {
    if(d.equals(mainList))
    {
    switch(((List)d).getSelectedIndex())
    {
    case 0:
    display.setCurrent(execlusiveList);
    break;
    case 1:
    display.setCurrent(implicitList);
    break;
    case 2:
    display.setCurrent(multipleList);
    break;
    }
    }
    }

    }
    else
    {
    if(c==CMD_BACK)
    {
    display.setCurrent(mainList);
    }
    }
    if(c==CMD_EXIT)
    {
    try {
    destroyApp(false);
    } catch (MIDletStateChangeException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    notifyDestroyed();
    }

    }

    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
    // TODO Auto-generated method stub

    }

    protected void pauseApp() {
    // TODO Auto-generated method stub

    }

    protected void startApp() throws MIDletStateChangeException {
    // TODO Auto-generated method stub
    Image[] imageArray=null;
    if(firstTime)
    {

    try {
    Image icon=Image.createImage("images/Icon.png");
    imageArray=new Image[]{icon,icon,icon};
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    String[] stringArray={"Exclusive","Implicit","Multiple"};
    mainList=new List("Choose type",Choice.IMPLICIT,stringArray,imageArray);
    mainList.addCommand(CMD_EXIT);
    mainList.setCommandListener(this);
    display.setCurrent(mainList);
    firstTime=false;
    }

    }

  • 相关阅读:
    MySql不同版本对表名大小写敏感!
    jQuery Intellisense in VS 2008
    控制台方式运行java程序示例
    有关SQL Server 2008安装时“安全程序支持规则”失败的解决方法
    正则表达式实现验证的技术总结
    网站开发架构设计要求
    jquery select控件的相关操作
    Windows Embedded Standard 7 开发随笔
    一步步做自己的webinstall安装包
    仿新浪新闻中异步替换关键字
  • 原文地址:https://www.cnblogs.com/Jasxu/p/javame_list.html
Copyright © 2020-2023  润新知