以文本方式查看主题

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

--  作者:admin
--  发布时间:2008/9/25 10:06:03
--  程序代码——ImageItem

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.ImageItem;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemCommandListener;
import javax.microedition.midlet.MIDlet;

public class Exec extends MIDlet implements ItemCommandListener {
        private Display display;
        private final static Command CMD_GO = new Command("Go", Command.ITEM, 1);
        
        public Exec() {
                display = Display.getDisplay(this);
        }

        public void startApp() {
                Image img = null;
                try {
                        img = Image.createImage("/pic.png");
                } catch (Exception e) {
                }
                Form f = new Form("ImageItem 测试");
                f.append(img);
                ImageItem ii1 = new ImageItem("图片1", img, Item.LAYOUT_CENTER
                                | Item.LAYOUT_NEWLINE_BEFORE, "图片1 取代文字", Item.BUTTON);
                ii1.addCommand(CMD_GO);
                ii1.setItemCommandListener(this);
                f.append(ii1);
                ImageItem ii2 = new ImageItem("图片2", img, Item.LAYOUT_RIGHT
                                | Item.LAYOUT_NEWLINE_BEFORE, "图片2 取代文字", Item.HYPERLINK);
                f.append(ii2);
                ii2.addCommand(CMD_GO);
                ii2.setItemCommandListener(this);
                display.setCurrent(f);
        }

        public void commandAction(Command c, Item i) {
                System.out.println(c.getLabel());
                System.out.println(i.getLabel());
        }

        public void pauseApp() {
        }

        public void destroyApp(boolean unconditional) {
        }
}

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