龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > Javascript编程 >

J2ME中ITEM类用法实例解析(1)(2)

时间:2013-03-06 14:58来源:未知 作者:admin 点击:
分享到:
4、代码(NETBEANS生成的大部分框架,笔者修改了其中几行,增加了ITEM类StateChanged方法) packagehello; importjavax.microedition.midlet.*; importjavax.microedition.lcdui.*; p

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

  1. packagehello;  
  2. importjavax.microedition.midlet.*;  
  3. importjavax.microedition.lcdui.*;  
  4.  
  5. publicclassHelloMIDletextendsMIDletimplementsCommandListener,
  6. ITEM类StateListener{  
  7. privatebooleanmidletPaused=false;  
  8. //  
  9. privateCommandexitCommand;  
  10. privateFormform;  
  11. privateChoiceGroupweather_CG;  
  12. //  
  13.  
  14. publicHelloMIDlet(){  
  15. }  
  16. //  
  17. //  
  18. //  
  19.  
  20. privatevoidinitialize(){  
  21. //writepre-initializeusercodehere  
  22.  
  23. //writepost-initializeusercodehere  
  24. }  
  25. //  
  26. //  
  27.  
  28. publicvoidstartMIDlet(){  
  29. //writepre-actionusercodehere  
  30. switchDisplayable(null,getForm());  
  31. //writepost-actionusercodehere  
  32. }  
  33. //  
  34. //  
  35. publicvoidresumeMIDlet(){  
  36. //writepre-actionusercodehere  
  37.  
  38. //writepost-actionusercodehere  
  39. }  
  40. //  
  41. //  
  42.  
  43. publicvoidswitchDisplayable(Alertalert,
  44. DisplayablenextDisplayable){  
  45. //writepre-switchusercodehere  
  46. Displaydisplay=getDisplay();  
  47. if(alert==null){  
  48. display.setCurrent(nextDisplayable);  
  49. }else{  
  50. display.setCurrent(alert,nextDisplayable);  
  51. }  
  52. //writepost-switchusercodehere  
  53. }  
  54. //  
  55. //  
  56.  
  57. publicvoidcommandAction(Commandcommand,
  58. Displayabledisplayable){  
  59. //writepre-actionusercodehere  
  60. if(displayable==form){  
  61. if(command==exitCommand){  
  62. //writepre-actionusercodehere  
  63. exitMIDlet();  
  64. //writepost-actionusercodehere  
  65. }  
  66. }  
  67. //writepost-actionusercodehere  
  68. }  
  69. //  
  70. //重写ITEM类StateChanged方法  
  71. publicvoidITEM类StateChanged(ITEM类ITEM类){  
  72. //writepre-actionusercodehere  
  73. if(ITEM类==weather_CG){  
  74. form.setTitle("你选择了"+weather_CG.getString
  75. (weather_CG.getSelectedIndex())+"天");  
  76. //writepost-actionusercodehere  
  77. }  
  78. //writepost-actionusercodehere  
  79. }  
  80. //  
  81.  
  82. //  
  83.  
  84. publicCommandgetExitCommand(){  
  85. if(exitCommand==null){  
  86. //writepre-initusercodehere  
  87. exitCommand=newCommand("u9000u51FA",Command.EXIT,0);  
  88. //writepost-initusercodehere  
  89. }  
  90. returnexitCommand;  
  91. }  
  92. //  
  93. //  
  94. publicFormgetForm(){  
  95. if(form==null){  
  96. //writepre-initusercodehere  
  97. form=newForm("Welcome",newITEM类[]{getWeather_CG()});  
  98. form.addCommand(getExitCommand());  
  99. form.setCommandListener(this);  
  100. //增加初始天气选择情况显示  
  101. form.setTitle("你选择了晴天");  
  102. //增加ITEM类的监听器  
  103. form.setITEM类StateListener(this);
  104. //writepost-initusercodehere  
  105. }  
  106. returnform;  
  107. }  
  108. //  
  109.  
  110. //  
  111.  
  112. publicChoiceGroupgetWeather_CG(){  
  113. if(weather_CG==null){  
  114. //writepre-initusercodehere  
  115. weather_CG=newChoiceGroup
  116. ("u5929u6C14u7C7Bu578B",Choice.EXCLUSIVE);  
  117. weather_CG.setLayout(ImageITEM类.LAYOUT_DEFAULT);  
  118. weather_CG.setFitPolicy(Choice.TEXT_WRAP_DEFAULT);  
  119. //选项框项的代码  
  120. weather_CG.append("晴",null);  
  121. weather_CG.append("阴",null);  
  122. weather_CG.append("雨",null);  
  123. weather_CG.append("雪",null);  
  124. weather_CG.setSelectedIndex(0,true);  
  125. //writepost-initusercodehere  
  126. }  
  127. returnweather_CG;  
  128. }  
  129. //  
  130.  
  131.  
  132.  
  133.  
  134. publicDisplaygetDisplay(){  
  135. returnDisplay.getDisplay(this);  
  136. }  
  137.  
  138. publicvoidexitMIDlet(){  
  139. switchDisplayable(null,null);  
  140. destroyApp(true);  
  141. notifyDestroyed();  
  142. }  
  143.  
  144. publicvoidstartApp(){  
  145. if(midletPaused){  
  146. resumeMIDlet();  
  147. }else{  
  148. initialize();  
  149. startMIDlet();  
  150. }  
  151. midletPaused=false;  
  152. }  
  153.  
  154. publicvoidpauseApp(){  
  155. midletPaused=true;  
  156. }  
  157.  
  158. publicvoiddestroyApp(booleanunconditional){  
  159. }  
  160. }  
  161.  

精彩图集

赞助商链接