自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

J2ME中ITEM類用法實(shí)例解析

開發(fā) 前端
本文向大家簡單介紹一下J2ME中ITEM類用法,Item類是Form類的派生類,通過改變Item類的派生類的實(shí)例的狀態(tài),用戶可以和應(yīng)用程序進(jìn)行交互。

你對J2ME中ITEM類用法是否熟悉,這里和大家簡單分享一下,為了便于大家理解通過圖里向大家解釋,相信本文介紹一定會(huì)讓你有所收獲。

J2ME中ITEM類用法

一、基本知識(shí)

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

2、通過改變ITEM類的派生類的實(shí)例的狀態(tài),用戶可以和應(yīng)用程序進(jìn)行交互。

3、ITEM類StateChanged方法和普通觸發(fā)器不同,在用戶引起狀態(tài)變化時(shí)自動(dòng)調(diào)用的操作,程序本身引起的不會(huì)調(diào)用。

二、創(chuàng)建實(shí)踐

1、以ChoiceGroup的應(yīng)用為例,所有應(yīng)用ITEM類的MIDlet如果要處理ITEM類的狀態(tài)變化必須重寫ITEM類StateChanged方法

2、實(shí)際運(yùn)行效果圖

實(shí)際運(yùn)行效果圖

3、NETBEANS設(shè)計(jì)器的設(shè)計(jì)

 #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("\u9000\u51FA",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類的監(jiān)聽器  
  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. ("\u5929\u6C14\u7C7B\u578B",Choice.EXCLUSIVE);  
  117. weather_CG.setLayout(ImageITEM類.LAYOUT_DEFAULT);  
  118. weather_CG.setFitPolicy(Choice.TEXT_WRAP_DEFAULT);  
  119. //選項(xiàng)框項(xiàng)的代碼  
  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.  

【編輯推薦】

  1. 深入探究J2ME Hashtable實(shí)現(xiàn)原理
  2. J2ME中的Display類的兩大作用
  3. J2ME數(shù)據(jù)結(jié)構(gòu)中Hashtable和Vector的使用
  4. MotorolaJ2ME開發(fā)時(shí)需要注意的幾個(gè)細(xì)節(jié)
  5. Java2平臺(tái)J2SE、J2EE、J2ME三大版本的區(qū)別

 

責(zé)任編輯:佚名 來源: blog.sina.com.cn
相關(guān)推薦

2010-09-30 12:53:00

J2MECSS

2010-09-29 08:57:04

J2ME前景

2010-09-29 13:23:12

J2MEPIM

2010-09-30 11:16:53

J2ME Snake腳

2010-09-29 13:50:31

J2MEJ2SE

2010-10-09 14:29:44

J2MEfontcolor

2010-09-29 12:45:50

J2ME

2009-06-23 11:30:16

RMSJ2ME

2010-09-29 10:15:35

JDKJ2EEJ2SE

2011-12-02 10:37:14

JavaJ2ME

2009-06-11 09:19:38

netbeans實(shí)例J2ME游戲

2010-09-29 09:19:39

J2ME開發(fā)工具

2010-09-29 15:17:22

J2MEDisplay類

2010-10-09 16:28:51

J2MEDisplay類

2010-09-29 09:59:22

J2ME配置

2010-09-30 08:49:17

cookieJ2ME

2010-09-29 15:45:49

J2MEFontColor

2009-06-17 11:27:00

setClip方法J2ME

2010-09-30 13:11:59

J2MECanvas

2009-06-30 15:49:00

J2ME編程
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)