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


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

主题:程序代码——ImageItem

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


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

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

 回到顶部