资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

J2ME中ITEM类如何使用

这篇文章给大家介绍J2ME中ITEM类如何使用,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

创新互联-成都网站建设公司,专注成都网站设计、成都做网站、网站营销推广,申请域名虚拟主机绵阳服务器托管有关企业网站制作方案、改版、费用等问题,请联系创新互联。

J2ME中ITEM类用法

一、基本知识

1、ITEM类是Form类的派生类。

2、通过改变ITEM类的派生类的实例的状态,用户可以和应用程序进行交互。

3、ITEM类StateChanged方法和普通触发器不同,在用户引起状态变化时自动调用的操作,程序本身引起的不会调用。

二、创建实践

1、以ChoiceGroup的应用为例,所有应用ITEM类的MIDlet如果要处理ITEM类的状态变化必须重写ITEM类StateChanged方法

2、实际运行效果图

J2ME中ITEM类如何使用

3、NETBEANS设计器的设计

J2ME中ITEM类如何使用

4、代码(NETBEANS生成的大部分框架,笔者修改了其中几行,增加了ITEM类StateChanged方法)

packagehello;  importjavax.microedition.midlet.*;  importjavax.microedition.lcdui.*;   publicclassHelloMIDletextendsMIDletimplementsCommandListener,ITEM类StateListener{  privatebooleanmidletPaused=false;  //  privateCommandexitCommand;  privateFormform;  privateChoiceGroupweather_CG;  //   publicHelloMIDlet(){  }  //  //  //   privatevoidinitialize(){  //writepre-initializeusercodehere   //writepost-initializeusercodehere  }  //  //   publicvoidstartMIDlet(){  //writepre-actionusercodehere  switchDisplayable(null,getForm());  //writepost-actionusercodehere  }  //  //  publicvoidresumeMIDlet(){  //writepre-actionusercodehere   //writepost-actionusercodehere  }  //  //   publicvoidswitchDisplayable(Alertalert,DisplayablenextDisplayable){  //writepre-switchusercodehere  Displaydisplay=getDisplay();  if(alert==null){  display.setCurrent(nextDisplayable);  }else{  display.setCurrent(alert,nextDisplayable);  }  //writepost-switchusercodehere  }  //  //   publicvoidcommandAction(Commandcommand,Displayabledisplayable){  //writepre-actionusercodehere  if(displayable==form){  if(command==exitCommand){  //writepre-actionusercodehere  exitMIDlet();  //writepost-actionusercodehere  }  }  //writepost-actionusercodehere  }  //  //重写ITEM类StateChanged方法  publicvoidITEM类StateChanged(ITEM类ITEM类){  //writepre-actionusercodehere  if(ITEM类==weather_CG){  form.setTitle("你选择了"+weather_CG.getString(weather_CG.getSelectedIndex())+"天");  //writepost-actionusercodehere  }  //writepost-actionusercodehere  }  //   //   publicCommandgetExitCommand(){  if(exitCommand==null){  //writepre-initusercodehere  exitCommand=newCommand("\u9000\u51FA",Command.EXIT,0);  //writepost-initusercodehere  }  returnexitCommand;  }  //  //  publicFormgetForm(){  if(form==null){  //writepre-initusercodehere  form=newForm("Welcome",newITEM类[]{getWeather_CG()});  form.addCommand(getExitCommand());  form.setCommandListener(this);  //增加初始天气选择情况显示  form.setTitle("你选择了晴天");  //增加ITEM类的监听器  form.setITEM类StateListener(this);//writepost-initusercodehere  }  returnform;  }  //   //   publicChoiceGroupgetWeather_CG(){  if(weather_CG==null){  //writepre-initusercodehere  weather_CG=newChoiceGroup("\u5929\u6C14\u7C7B\u578B",Choice.EXCLUSIVE);  weather_CG.setLayout(ImageITEM类.LAYOUT_DEFAULT);  weather_CG.setFitPolicy(Choice.TEXT_WRAP_DEFAULT);  //选项框项的代码  weather_CG.append("晴",null);  weather_CG.append("阴",null);  weather_CG.append("雨",null);  weather_CG.append("雪",null);  weather_CG.setSelectedIndex(0,true);  //writepost-initusercodehere  }  returnweather_CG;  }  //      publicDisplaygetDisplay(){  returnDisplay.getDisplay(this);  }   publicvoidexitMIDlet(){  switchDisplayable(null,null);  destroyApp(true);  notifyDestroyed();  }   publicvoidstartApp(){  if(midletPaused){  resumeMIDlet();  }else{  initialize();  startMIDlet();  }  midletPaused=false;  }   publicvoidpauseApp(){  midletPaused=true;  }   publicvoiddestroyApp(booleanunconditional){  }  }

关于J2ME中ITEM类如何使用就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。


网页名称:J2ME中ITEM类如何使用
新闻来源:http://cdkjz.cn/article/gdpgip.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220