用户名: 密码: 免费注册 忘记密码? 网站地图 | 加入收藏 | 设为首页
首页 | 新闻 | 工具 | 系统 | 办公 | 聊天 | 多媒体 | 网页 | 运营 | 平面 | 欣赏 | 数据库 | 程序 | 服务器 | 组网
网页 | 3dmax | Ghost | Windows Xp| Dreamweaver | photoshop | Flash | office | Alexa | Css | QQ | Asp | PHP | Jsp | Access
Flash MX 2004入门 | 网站推广策略 | CorelDRAW入门 | ASP学习 | 网站建设大师功 | Word入门
  iTbulo.com > 学院 > 程序开发教程 > JSP教程 > Jsp开发技巧 > 文章正文
我的J2ME编程练习(5)——ImageItem
iTbulo.COM 2005-4-13 佚名()

/* * imageItemlet.java * * Created on 2005年4月17日, 下午8:56 */

import javax.microedition.midlet.*;import javax.microedition.lcdui.*;

/** * * @author  Administrator * @version */public class imageItemlet extends MIDlet implements CommandListener,ItemCommandListener{        private Form aForm;    private Image sohuImage;    private Image neImage;    private ImageItem sohuImageItem;    private ImageItem neImageItem;    private Display aDisplay;    private Command exitCommand;    private Command connectCommand;    private Spacer aSpacer;    private Alert anAlert;            public imageItemlet() {        aForm=new Form("ImageItemTest");        exitCommand=new Command("EXIT",Command.EXIT,1);        connectCommand=new Command("Connect",Command.ITEM,2);        aSpacer=new Spacer(10,2);        anAlert=new Alert("Connecting...","Connecting to www.163.com ...",                null,AlertType.INFO);        try{            sohuImage=Image.createImage("/sohu.png");            sohuImageItem=new ImageItem(null,sohuImage,ImageItem.LAYOUT_RIGHT,                    "This is Sohu!");                        aSpacer.setLayout(Item.LAYOUT_EXPAND);

            //The profram will connect to www.163.com and display the Alert            //when click the ImageItem of 163.png .

            neImage=Image.createImage("/163.png");            neImageItem=new ImageItem(null,neImage,ImageItem.LAYOUT_RIGHT,                    "This is 163",Item.HYPERLINK);            neImageItem.setItemCommandListener(this);            neImageItem.setDefaultCommand(connectCommand);                        aForm.append(sohuImageItem);            aForm.append(aSpacer);            aForm.append(neImageItem);            aForm.addCommand(exitCommand);            aForm.setCommandListener(this);        }                        catch (Exception e){            e.printStackTrace();        }            }    public void startApp() {        aDisplay=Display.getDisplay(this);        aDisplay.setCurrent(aForm);    }        public void pauseApp() {    }        public void destroyApp(boolean unconditional) {    }        public void commandAction(Command c,Displayable d){        if(c==exitCommand){            destroyApp(false);            notifyDestroyed();        }    }        public void commandAction(Command c,Item i){        if(c==connectCommand){            aDisplay.setCurrent(anAlert,aForm);        }    }        }

这个程序的比较新的地方在于使用了midp2.0中新增加的ITEM类的外观模式和SPACER类。其中外观模式的使用在StringItem中已经介绍过了。

public Spacer(int minWidth, int minHeight),SPACER类在本程序中设置为Item.LAYOUT_EXPAND,即填充剩余的空白部分。这样,运行后可以看到两个ImageItem对象分别位于左右两端,布局上好看一些。
文章搜索
相关资讯
相关文章 相关下载
我的特“色”建站过程
SYBASE产品全面支持J2EE
Sun公司提交新规范 J2SE 6.0初见雏形
我的输入法哪里去了呢?
请住手:我的QQ你别用
焦点信息