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


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

主题:程序代码——StringItem

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


加好友 发短信 管理员
等级:管理员 帖子:1949 积分:26803 威望:0 精华:34 注册:2003/12/30 16:34:32
程序代码——StringItem  发帖心情 Post By:2008/9/25 10:05:22 [显示全部帖子]

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemCommandListener;
import javax.microedition.lcdui.StringItem;
import javax.microedition.midlet.MIDlet;

public class Exec extends MIDlet implements CommandListener,
                ItemCommandListener {
        private Display display;
        private Form mainForm;
        private final static Command CMD_GO = new Command("Go", Command.ITEM, 1);
        private final static Command CMD_PRESS = new Command("Press", Command.ITEM,
                        1);
        private final static Command CMD_EXIT = new Command("Exit", Command.EXIT, 1);

        protected void startApp() {
                display = Display.getDisplay(this);
                mainForm = new Form("String Item Demo");
                mainForm.append("This is a simple label");
                StringItem item = new StringItem("This is a StringItem label: ",
                                "This is the StringItems text");
                mainForm.append(item);
                item = new StringItem("Short label: ", "text");
                mainForm.append(item);
                item = new StringItem("Hyper-Link ", "hyperlink", Item.HYPERLINK);
                item.setDefaultCommand(CMD_GO);
                item.setItemCommandListener(this);
                mainForm.append(item);
                item = new StringItem("Button ", "Button", Item.BUTTON);
                item.setDefaultCommand(CMD_PRESS);
                item.setItemCommandListener(this);
                mainForm.append(item);
                mainForm.addCommand(CMD_EXIT);
                mainForm.setCommandListener(this);
                display.setCurrent(mainForm);
        }

        public void commandAction(Command c, Item item) {
                if (c == CMD_GO) {
                        String text = "Go to the URL...";
                        Alert a = new Alert("URL", text, null, AlertType.INFO);
                        display.setCurrent(a);
                } else if (c == CMD_PRESS) {
                        String text = "Do an action...";
                        Alert a = new Alert("Action", text, null, AlertType.INFO);
                        display.setCurrent(a);
                }
        }

        public void commandAction(Command c, Displayable d) {
                destroyApp(false);
                notifyDestroyed();
        }

        protected void destroyApp(boolean unconditional) {
        }

        protected void pauseApp() {
        }
}

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

 回到顶部