欢迎光临
我们一直在努力

我的J2ME编程练习(5)——ImageItem-JSP教程,Java技巧及代码

建站超值云服务器,限时71元/月

/* * 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对象分别位于左右两端,布局上好看一些。

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 我的J2ME编程练习(5)——ImageItem-JSP教程,Java技巧及代码
分享到: 更多 (0)

相关推荐

  • 暂无文章