MIDP高级UI的使用(二)List组件 - 编程入门网
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-06-25
16. * @author pengjw 17. */ 18. public class ListDemo extends MIDlet implements CommandListener{ 19. private static final Command CMD_EXIT = new Command("Exit",Command.EXIT,1); 20. private static final Command CMD_BACK = new Command("Back",Command.BACK,1); 21. private Display display; 22. private List mainList; 23. private List exclusiveList; 24. private List implicitList; 25. private List mutipleList; 26. private boolean firstTime; 27. private Image[] imageArray; 28. public ListDemo(){ 29. display = Display.getDisplay(this); 30. String[] stringArray = { 31. "Option A", 32. "Option B", 33. "Option C", 34. "Option D" 35. }; 36. imageArray = null; 37. //ExlcusiveList 的声明 38. exclusiveList = new List("Exclusive",Choice.EXCLUSIVE,stringArray,imageArray); 39. exclusiveList.addCommand(CMD_BACK); 40. exclusiveList.addCommand(CMD_EXIT); 41. exclusiveList.setCommandListener(this); 42. //ImplicitList 的声明 43. implicitList = new List("Implicit",Choice.IMPLICIT,stringArray,imageArray); 44. implicitList.addCommand(CMD_BACK); 45. implicitList.addCommand(CMD_EXIT); 46. implicitList.setCommandListener(this); 47. //MutipleListde 的声明 48. mutipleList = new List("Multiple",Choice.MULTIPLE,stringArray,imageArray); 49. mutipleList.addCommand(CMD_BACK); 50. mutipleList.addCommand(CMD_EXIT); 51. mutipleList.setCommandListener(this); 52. } 53. public void startApp() { 54. if(firstTime){ 55. imageArray = null; 56. } 57. try { 58. //注意这里的图片路径是相对的,图片格式应该为png 59. Image icon = Image.createImage("/images/java.png"); 60. imageArray = new Image[]{ 61. icon, 62. icon, 63. icon 64. }; 65. } catch (Exception e) { 66. e.printStackTrace(); 67. } 68. String[] stringArray = { 69. "Exclusiver", 70. "Implicit", 71. "Multiple" 72. }; 73. //mainList主菜单 74. mainList = new List("Choose Type",Choice.IMPLICIT,stringArray,imageArray); 75. mainList.addCommand(CMD_EXIT); 76. mainList.setCommandListener(this); 77. display.setCurrent(mainList); 78. firstTime = false; 79. } 80. public void pauseApp() { 81. } 82. public void destroyApp(boolean unconditional) { 83. } 84. //实现CommandListener接口的commandAction方法 85. public void commandAction(Command c, Displayable d) { 86. if(d.equals(mainList)){ 87. if(c==List.SELECT_COMMAND){ 88. if(d.equals(mainList)){ 89. switch(((List)d).getSelectedIndex()){ 90. case 0: 91. display.setCurrent(exclusiveList); 92. break; 93. case 1: 94. display.setCurrent(implicitList); 95. break; 96. case 2: 97. display.setCurrent(mutipleList); 98. break; |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于MIDP高级UI的使用(二)List组件 - 编程入门网的所有评论