J2ME GUI实战之三 ----------LWUIT实现切换特效

本文来自:http://blog.csdn.net/hellogv/ ,转载必须注明出处!

J2ME GUI实战之三 ----------LWUIT实现切换特效 J2ME GUI实战之三 ----------LWUIT实现切换特效
以上第一幅图是窗体切换特效之一;第二幅图是控件切换特效之一

以下给出设置特效的代码,这些代码同样来自Sample例子中:
  1. /*
  2. *Copyright?2008SunMicrosystems,Inc.Allrightsreserved.
  3. *Useissubjecttolicenseterms.
  4. *
  5. */
  6. packagecom.sun.lwuit.uidemo;
  7. importcom.sun.lwuit.Button;
  8. importcom.sun.lwuit.ButtonGroup;
  9. importcom.sun.lwuit.CheckBox;
  10. importcom.sun.lwuit.Command;
  11. importcom.sun.lwuit.Component;
  12. importcom.sun.lwuit.Container;
  13. importcom.sun.lwuit.Dialog;
  14. importcom.sun.lwuit.Display;
  15. importcom.sun.lwuit.Form;
  16. importcom.sun.lwuit.Label;
  17. importcom.sun.lwuit.M3G;
  18. importcom.sun.lwuit.RadioButton;
  19. importcom.sun.lwuit.TextArea;
  20. importcom.sun.lwuit.TextField;
  21. importcom.sun.lwuit.animations.CommonTransitions;
  22. importcom.sun.lwuit.animations.Transition;
  23. importcom.sun.lwuit.animations.Transition3D;
  24. importcom.sun.lwuit.events.ActionEvent;
  25. importcom.sun.lwuit.events.ActionListener;
  26. importcom.sun.lwuit.layouts.BoxLayout;
  27. importcom.sun.lwuit.layouts.FlowLayout;
  28. importcom.sun.lwuit.plaf.Style;
  29. /**
  30. *Transitonsbetweenscreens
  31. *
  32. *@authorShaiAlmog
  33. */
  34. publicclassTransitionDemoextendsDemo{
  35. /**
  36. *Theselectedradiobuttonindex
  37. */
  38. privatestaticintselectedIndex=0;
  39. publicStringgetName(){
  40. return"Transitions";
  41. }
  42. protectedStringgetHelp(){
  43. return"Transitionsappearwhenswitchingfromoneformtothenext,atransitioncanbebound"+
  44. "totheoperationofexitingorenteringthescreen.Therearedefaulttransitionsinthetoolkit"+
  45. "andcustomtransitionsareeasytowrite.";
  46. }
  47. privateRadioButtoncreateRB(Stringlabel,ButtonGroupg,Formf){
  48. RadioButtonb=newRadioButton(label);
  49. Styles=b.getStyle();
  50. s.setMargin(0,0,0,0);
  51. s.setBgTransparency(70);
  52. g.add(b);
  53. f.addComponent(b);
  54. returnb;
  55. }
  56. protectedvoidexecute(finalFormf){
  57. f.setLayout(newBoxLayout(BoxLayout.Y_AXIS));
  58. Labeltitle=newLabel("Pleaseselectatransitiontype:");
  59. title.getStyle().setMargin(0,0,0,0);
  60. title.getStyle().setBgTransparency(70);
  61. f.addComponent(title);
  62. finalButtonGroupradioButtonGroup=newButtonGroup();
  63. createRB("SlideHorizontal",radioButtonGroup,f);
  64. createRB("SlideVertical",radioButtonGroup,f);
  65. createRB("Fade",radioButtonGroup,f);
  66. if(M3G.isM3GSupported()){
  67. createRB("Rotate",radioButtonGroup,f);
  68. createRB("FlyIn",radioButtonGroup,f);
  69. createRB("Cube",radioButtonGroup,f);
  70. createRB("StaticRotation",radioButtonGroup,f);
  71. createRB("SwingTop",radioButtonGroup,f);
  72. createRB("SwingBottom",radioButtonGroup,f);
  73. }
  74. radioButtonGroup.setSelected(selectedIndex);
  75. finalTextFieldspeed=newTextField("500");
  76. speed.setConstraint(TextArea.NUMERIC);
  77. speed.setInputModeOrder(newString[]{"123"});
  78. f.addComponent(createPair("Speed",speed));
  79. finalFormdestination=newForm("Destination");
  80. destination.addComponent(newLabel("Thisisthetransitiondestination..."));
  81. destination.addCommand(newCommand("Back"){
  82. publicvoidactionPerformed(ActionEventevt){
  83. f.show();
  84. }
  85. });
  86. finalCheckBoxhighQuality=newCheckBox("HighQuality");
  87. highQuality.setSelected(!Display.getInstance().isLightMode());
  88. highQuality.getStyle().setBgTransparency(0);
  89. f.addComponent(highQuality);
  90. highQuality.addActionListener(newActionListener(){
  91. publicvoidactionPerformed(ActionEventevt){
  92. if(Display.getInstance().isLightMode()){
  93. Dialog.show("Warning","Thedeviceseemsabitweakforhighqualityrendering,"+
  94. "usingthismodemightcrashyourdevice.","OK",null);
  95. }
  96. }
  97. });
  98. finalButtonupdateButton=newButton("PreviewTransition");
  99. finalButtonapplyButton=newButton("ApplyTransition");
  100. finalButtonapplyMenu=newButton("ApplyToMenu");
  101. finalButtonapplyComponents=newButton("ApplyToComponents");
  102. updateButton.setAlignment(Button.CENTER);
  103. updateButton.getStyle().setPadding(5,5,7,7);
  104. applyButton.setAlignment(Button.CENTER);
  105. applyButton.getStyle().setPadding(5,5,7,7);
  106. ActionListenerlistener=newActionListener(){
  107. publicvoidactionPerformed(ActionEventev){
  108. intrunSpeed=Integer.parseInt(speed.getText());
  109. Transitionin,out;//in表示窗体切入时使用的特效,out表示窗体切出时使用的特性
  110. switch(radioButtonGroup.getSelectedIndex()){
  111. case0:{
  112. out=CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL,false,runSpeed);
  113. in=CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL,true,runSpeed);
  114. break;
  115. }
  116. case1:{
  117. out=CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL,false,runSpeed);
  118. in=CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL,true,runSpeed);
  119. break;
  120. }
  121. case2:{
  122. out=CommonTransitions.createFade(runSpeed);
  123. in=CommonTransitions.createFade(runSpeed);
  124. break;
  125. }
  126. case3:{
  127. out=Transition3D.createRotation(runSpeed,true);
  128. in=Transition3D.createRotation(runSpeed,false);
  129. break;
  130. }
  131. case4:{
  132. out=Transition3D.createFlyIn(runSpeed);
  133. in=Transition3D.createFlyIn(runSpeed);
  134. break;
  135. }
  136. case5:{
  137. out=Transition3D.createCube(runSpeed,true);
  138. in=Transition3D.createCube(runSpeed,false);
  139. break;
  140. }
  141. case6:{
  142. out=Transition3D.createStaticRotation(runSpeed,true);
  143. in=Transition3D.createStaticRotation(runSpeed,false);
  144. break;
  145. }
  146. case7:{
  147. out=Transition3D.createSwingIn(runSpeed);
  148. in=out;
  149. break;
  150. }
  151. default:{
  152. out=Transition3D.createSwingIn(runSpeed,false);
  153. in=out;
  154. break;
  155. }
  156. }
  157. selectedIndex=radioButtonGroup.getSelectedIndex();
  158. if(outinstanceofTransition3D){//这里需要设置特效效果,仅对部分特效有效
  159. ((Transition3D)out).setHighQualityMode(highQuality.isSelected());
  160. ((Transition3D)in).setHighQualityMode(highQuality.isSelected());
  161. }
  162. if(updateButton==ev.getSource()){
  163. //演示窗体切换特效
  164. f.setTransitionOutAnimator(out);
  165. f.setTransitionInAnimator(in);
  166. destination.show();
  167. }
  168. elseif(applyButton==ev.getSource()){
  169. //设置全部窗体在切换时都是同一个特效,注意是“窗体切换时”
  170. f.setTransitionOutAnimator(null);
  171. f.setTransitionInAnimator(null);
  172. UIDemoMIDlet.setTransition(in,out);
  173. }
  174. /*这个函数是UIDemoMIDlet的成员函数
  175. *publicstaticvoidsetTransition(Transitionin,Transitionout){
  176. form.setTransitionInAnimator(in);
  177. form.setTransitionOutAnimator(out);
  178. }
  179. */
  180. elseif(applyMenu==ev.getSource()){
  181. //设置全部菜单都是同一个特效,菜单Menu就是一般在右下角弹出的
  182. UIDemoMIDlet.setMenuTransition(in,out);
  183. }
  184. /*这个函数是UIDemoMIDlet的成员函数
  185. *publicstaticvoidsetMenuTransition(Transitionin,Transitionout){
  186. form.setMenuTransitions(in,out);
  187. UIManager.getInstance().getLookAndFeel().setDefaultMenuTransitionIn(in);
  188. UIManager.getInstance().getLookAndFeel().setDefaultMenuTransitionOut(out);
  189. }
  190. */
  191. elseif(applyComponents==ev.getSource()){
  192. //设置控件都是同一个特效,这里的控件可以是Button
  193. //当Button被选中时就会显示特效
  194. UIDemoMIDlet.setComponentTransition(in);
  195. }
  196. /*这个函数是UIDemoMIDlet的成员函数
  197. *publicstaticvoidsetComponentTransition(Transitiont){
  198. componentTransitions=t;
  199. form.setSmoothScrolling(false);
  200. }
  201. */
  202. }
  203. };
  204. updateButton.addActionListener(listener);
  205. applyButton.addActionListener(listener);
  206. applyMenu.addActionListener(listener);
  207. applyComponents.addActionListener(listener);
  208. ContainerbuttonPanel=newContainer(newFlowLayout(Component.CENTER));
  209. buttonPanel.addComponent(updateButton);
  210. f.addComponent(buttonPanel);
  211. buttonPanel=newContainer(newFlowLayout(Component.CENTER));
  212. buttonPanel.addComponent(applyButton);
  213. f.addComponent(buttonPanel);
  214. buttonPanel=newContainer(newFlowLayout(Component.CENTER));
  215. buttonPanel.addComponent(applyMenu);
  216. f.addComponent(buttonPanel);
  217. buttonPanel=newContainer(newFlowLayout(Component.CENTER));
  218. buttonPanel.addComponent(applyComponents);
  219. f.addComponent(buttonPanel);
  220. }
  221. }


你可能感兴趣的:(.net,Blog,F#,sun)