J2ME GUI实战之七 ----------LWUIT的Tabbed分页、Text文本

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

首先,想让大家看看本例实现之后的动画:


首先,先来说说“分页”,Win32控件中,有种控件叫做Tab,这个功能是把一个窗体分层,同时可以容纳更多控件(注:这里的分页并不是B/S的网络数据库中的分页)。
在J2ME中实现Tab,可谓是件好事,包含Tab控件的Class可以作为主类,从而根据需求关联更多的应用。然后,使用Tab效果最好的是触摸屏手机...........
LWUIT里的Text控件,跟原来的Text控件差不多,很多人都疑惑:Text控件输入汉字时,到底是用高级的输入框,还是在当前界面输入........答案是调用高级输入框!
OK,废话少说,直接来代码,这里的代码也是修改自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.Command;
  10. importcom.sun.lwuit.Container;
  11. importcom.sun.lwuit.Dialog;
  12. importcom.sun.lwuit.Form;
  13. importcom.sun.lwuit.Label;
  14. importcom.sun.lwuit.RadioButton;
  15. importcom.sun.lwuit.TabbedPane;
  16. importcom.sun.lwuit.TextArea;
  17. importcom.sun.lwuit.TextField;
  18. importcom.sun.lwuit.events.ActionEvent;
  19. importcom.sun.lwuit.events.ActionListener;
  20. importcom.sun.lwuit.layouts.BorderLayout;
  21. importcom.sun.lwuit.layouts.BoxLayout;
  22. /**
  23. *本例演示如何使用Tabbed、Text控件
  24. */
  25. publicclassTabbedPaneDemoimplementsActionListener{
  26. publicFormform=newForm("TabbedPaneDemo");
  27. privateCommandbackCommand=newCommand("Back",1);
  28. finalTextAreatitle;
  29. finalTextAreabody;
  30. TabbedPanetp=null;
  31. TabbedPaneDemo(){
  32. form.setLayout(newBorderLayout());
  33. form.setScrollable(false);
  34. form.addCommand(backCommand);
  35. form.setCommandListener(this);
  36. tp=newTabbedPane();
  37. //addTab可以为页面添加控件,也可以是Container(相当于容器的控件)
  38. tp.addTab("Tab1",newLabel("WelcometoTabbedPanedemo!"));
  39. //---------------------第二页的内容------------------------------------
  40. //Container就是一个控件,只不过相当于容器,建议每页有自己的事件处理
  41. ContainerradioButtonsPanel=newContainer(newBoxLayout(BoxLayout.Y_AXIS));
  42. RadioButtontopRB=newRadioButton("Top");
  43. RadioButtonLeftRB=newRadioButton("Left");
  44. RadioButtonBottomRB=newRadioButton("Bottom");
  45. RadioButtonRightRB=newRadioButton("Right");
  46. RadioListenerrbListener=newRadioListener();//自定义接收事件的类
  47. topRB.addActionListener(rbListener);
  48. LeftRB.addActionListener(rbListener);
  49. BottomRB.addActionListener(rbListener);
  50. RightRB.addActionListener(rbListener);
  51. ButtonGroupgroup1=newButtonGroup();
  52. group1.add(topRB);
  53. group1.add(LeftRB);
  54. group1.add(BottomRB);
  55. group1.add(RightRB);
  56. radioButtonsPanel.addComponent(newLabel("Pleasechooseatabplacementdirection:"));
  57. radioButtonsPanel.addComponent(topRB);
  58. radioButtonsPanel.addComponent(LeftRB);
  59. radioButtonsPanel.addComponent(BottomRB);
  60. radioButtonsPanel.addComponent(RightRB);
  61. tp.addTab("Tab2",radioButtonsPanel);
  62. //----------------------第三页的内容----------------------------------
  63. //Container就是一个控件,只不过相当于容器,建议每页有自己的事件处理
  64. ContainerTextPanel=newContainer(newBoxLayout(BoxLayout.Y_AXIS));
  65. ButtonListenertxtListener=newButtonListener();//按钮事件处理
  66. title=newTextField("Title");
  67. title.getStyle().setBgTransparency(100);
  68. body=newTextArea("Thisisthebodyofthealert....",3,20);
  69. body.getStyle().setBgTransparency(100);
  70. finalButtonShowMessage=newButton("ok");
  71. ShowMessage.getStyle().setBgTransparency(100);
  72. ShowMessage.addActionListener(txtListener);
  73. TextPanel.addComponent(title);
  74. TextPanel.addComponent(body);
  75. TextPanel.addComponent(ShowMessage);
  76. tp.addTab("Tab3",TextPanel);
  77. form.addComponent("Center",tp);
  78. }
  79. /**监听radiobuttons事件*/
  80. classRadioListenerimplementsActionListener{
  81. publicvoidactionPerformed(ActionEvente){
  82. Stringtitle=((RadioButton)e.getSource()).getText();
  83. Dialog.show("TabbedPaneDemo",title,"OK",null);
  84. }
  85. }
  86. /**监听buttons事件*/
  87. classButtonListenerimplementsActionListener{
  88. publicvoidactionPerformed(ActionEvente){
  89. Dialog.show(title.getText(),body.getText(),"OK",null);
  90. }
  91. }
  92. /**监听command事件*/
  93. publicvoidactionPerformed(ActionEventarg0){
  94. UIDemoMIDlet.backToMainMenu();
  95. }
  96. }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值