日期:2014-05-20  浏览次数:20842 次

设计可组装的j2me UI(七) Choice
?? 艾,不想解释了。贴代码算了
java 代码
?
  1. /********************************************************************?
  2. ?*??
  3. ?*?版权说明,此程序仅供学习参考。不能用于商业?
  4. ?*??
  5. ?********************************************************************/??
  6. package?org.pook.ui;??
  7. ??
  8. import?javax.microedition.lcdui.Graphics;??
  9. import?javax.microedition.lcdui.Image;??
  10. ??
  11. import?org.pook.ui.core.Platform;??
  12. ???
  13. ???
  14. ??
  15. /**?
  16. ?*?<b>类名:ChoiceGroup.java</b>?</br>??
  17. ?*?编写日期:?2006-9-19?<br/>?
  18. ?*?程序功能描述???本Class是一个多选择列表,因为项目的原??,此列表是??个固定形式的<br/>?
  19. ?*?可以在Form上进行添加删??,只不过表现形式固??<br/>?
  20. ?*?Demo:?<br/>?
  21. ?*?Bug:?<br/>?
  22. ?*??
  23. ?*?程序变更日期???<br/>??
  24. ?*?变更作??????<br/>??
  25. ?*?变更说明???<br/>?
  26. ?*??
  27. ?*?@author?wuhua?</br>?<a?href="mailto:rrq12345@163.com">rrq12345@163.com</a>?
  28. ?*/??
  29. public?class?Choice?extends?Part?{??
  30. ??????
  31. ???????
  32. ????private?boolean??select;??
  33. ??????
  34. ????/**?显示选择状????*/??
  35. ????private?Image[]?imageElements;??
  36. ???
  37. ???
  38. ??????
  39. ????public?Choice(String?label,??
  40. ????????????Image[]?imageElements,?boolean??select)?{??
  41. ????????super(0,?0,?0,?0);??
  42. ????????if(label?==?null)??
  43. ????????????label?=?"";??
  44. ????????this.label?=?label;??
  45. ????????this.select?=?select;??
  46. ????????this.imageElements?=?imageElements;??
  47. ???????
  48. ????}??
  49. ??
  50. ???????
  51. ????public?void?paint(Graphics?g)?{??
  52. ????????paintChoiceImpl(g);??
  53. ??
  54. ????}??
  55. ??
  56. ????private?void?paintChoiceImpl(Graphics?g)?{??
  57. ???????
  58. ????????paintChoice(g);??
  59. ??????????
  60. ????}??
  61. ??
  62. ??????
  63. ??????
  64. ????private?void?paintChoice(Graphics?g)?{??
  65. ????????g.drawImage(select?imageElements[0]:imageElements[1],view[X],?view[Y],??
  66. ????????????????????Graphics.TOP|Graphics.LEFT);??
  67. ????????paintLabel(g);??
  68. ??????????
  69. ????}??
  70. ????private?void?paintLabel(Graphics?g)?{??
  71. ????????if(label.equals(""))??
  72. ????????????return;??
  73. ????????g.setColor(fontColor);??
  74. ????????g.drawString(label,view[X]?+?imageElements[0].getWidth()?+?4,?view[Y]-2,?Graphics.TOP?|?Graphics.LEFT);??
  75. ??????????
  76. ????????if(hasFocus)??
  77. ????????????paintSelect(g);??
  78. ????}??
  79. ??????
  80. ???????
  81. ??
  82. ????/**?绘制选择???**/??
  83. ????private?void?paintSelect(Graphics?g)?{??
  84. ????????g.drawRect(view[X]?-?1,?view[Y]??-?1,???
  85. ???????????????????imageElements[0].getWidth()??+?1,??
  86. ??????????????????imageElements[0].getHeight()?+?1);??
  87. ???????????????????
  88. ??????????
  89. ????}??
  90. ??
  91. ??
  92. ????public?void?onClick(int?keyCode)?{??
  93. ????????if(keyCode?==?Platform.KEY_ENTER???
  94. ????????????????&&?hasFocus)??
  95. ????????????select?=?!select;??
  96. ??
  97. ????}??
  98. ??
  99. ??
  100. ????public?boolean?isSelect()?{??
  101. ????????return?select;??
  102. ????}??
  103. ??
  104. ??
  105. ????public?void?setSelect(boolean?select)?{??
  106. ????????this.select?=?select;??
  107. ????}??
  108. ??
  109. }??
1 楼 linginfanta 2007-02-25  
代码不全