课外天地 李树青学习天地JavaME移动开发课件 → 程序代码——List


  共有15680人关注过本帖树形打印复制链接

主题:程序代码——List

帅哥哟,离线,有人找我吗?
admin
  1楼 博客 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 管理员
等级:管理员 帖子:1949 积分:26803 威望:0 精华:34 注册:2003/12/30 16:34:32
程序代码——List  发帖心情 Post By:2008/9/22 23:12:58 [只看该作者]

import javax.microedition.lcdui.Alert;
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;

public class Exec extends MIDlet implements CommandListener {
        Display display;

        final int count = 4;

        Image[] icons = null;

        String[] listItemLabels = null;

        List list1 = null;

        Command cmd1 = new Command("显示", Command.ITEM, 1);

        public void startApp() {
                display = Display.getDisplay(this);
                try {
                        icons = new Image[count];
                        listItemLabels = new String[count];

                        for (int i = 0; i < count; i++) {
                                icons = Image.createImage("/images/icon" + (i + 1) + ".png");
                                listItemLabels = "icon" + (i + 1) + ".png";
                        }
                } catch (Exception e) {
                        System.out.println(e.getMessage());
                }
                list1 = new List("主界面", Choice.IMPLICIT, listItemLabels, icons);
                list1.addCommand(cmd1);
                list1.setSelectCommand(cmd1);
                list1.setCommandListener(this);
                display.setCurrent(list1);
        }

        public void pauseApp() {
        }

        public void destroyApp(boolean unconditional) {
        }

        public void commandAction(Command c, Displayable s) {
                String title = list1.getString(list1.getSelectedIndex());
                Image image = null;
                try {
                        image = Image.createImage("/images/" + title);
                } catch (Exception e) {
                        System.out.println(e.getMessage());
                }
                Alert alert = new Alert("显示");
                alert.setString(title);
                alert.setImage(image);
                alert.setTimeout(2000);
                display.setCurrent(alert);
        }
}

 

 

 

[此贴子已经被作者于2010-12-12 18:28:30编辑过]

 回到顶部