网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

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://bjjierui.cn/article/gdpgip.html

其他资讯