你对J2ME中ITEM类用法是否熟悉,这里和大家简单分享一下,为了便于大家理解通过图里向大家解释,相信本文介绍一定会让你有所收获。

成都创新互联公司是专业的涪城网站建设公司,涪城接单;提供网站建设、网站制作,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行涪城网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
J2ME中ITEM类用法
一、基本知识
1、ITEM类是Form类的派生类。
2、通过改变ITEM类的派生类的实例的状态,用户可以和应用程序进行交互。
3、ITEM类StateChanged方法和普通触发器不同,在用户引起状态变化时自动调用的操作,程序本身引起的不会调用。
二、创建实践
1、以ChoiceGroup的应用为例,所有应用ITEM类的MIDlet如果要处理ITEM类的状态变化必须重写ITEM类StateChanged方法
2、实际运行效果图
3、NETBEANS设计器的设计
#p#
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类用法实例解析
                
                URL标题:http://www.csdahua.cn/qtweb/news12/524162.html
            
网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网