以文本方式查看主题

-  课外天地 李树青  (http://njcie.com/bbs/index.asp)
--  JavaME移动开发课件  (http://njcie.com/bbs/list.asp?boardid=18)
----  程序代码——List  (http://njcie.com/bbs/dispbbs.asp?boardid=18&id=535)

--  作者:admin
--  发布时间:2008/9/22 23:12:58
--  程序代码——List

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编辑过]