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 ?2008 Sun Microsystems, Inc. All rights reserved.
  3.  * Use is subject to license terms.
  4.  *
  5.  */
  6. package com.sun.lwuit.uidemo;
  7. import com.sun.lwuit.Button;
  8. import com.sun.lwuit.ButtonGroup;
  9. import com.sun.lwuit.Command;
  10. import com.sun.lwuit.Container;
  11. import com.sun.lwuit.Dialog;
  12. import com.sun.lwuit.Form;
  13. import com.sun.lwuit.Label;
  14. import com.sun.lwuit.RadioButton;
  15. import com.sun.lwuit.TabbedPane;
  16. import com.sun.lwuit.TextArea;
  17. import com.sun.lwuit.TextField;
  18. import com.sun.lwuit.events.ActionEvent;
  19. import com.sun.lwuit.events.ActionListener;
  20. import com.sun.lwuit.layouts.BorderLayout;
  21. import com.sun.lwuit.layouts.BoxLayout;
  22. /**
  23.  * 本例演示如何使用Tabbed、Text控件
  24.  */
  25. public class TabbedPaneDemo implements ActionListener {
  26.     public Form form = new Form("TabbedPaneDemo");
  27.     private  Command backCommand = new Command("Back"1);
  28.     final TextArea title ;
  29.     final TextArea body;
  30.     TabbedPane tp = null;
  31.     TabbedPaneDemo() {
  32.         form.setLayout(new BorderLayout());
  33.         form.setScrollable(false);
  34.         form.addCommand(backCommand);
  35.         form.setCommandListener(this);
  36.         tp = new TabbedPane();
  37.         //addTab可以为页面添加控件,也可以是Container(相当于容器的控件)
  38.         tp.addTab("Tab 1"new Label("Welcome to TabbedPane demo!"));
  39.         //---------------------第二页的内容------------------------------------
  40.         //Container就是一个控件,只不过相当于容器,建议每页有自己的事件处理
  41.         Container radioButtonsPanel = new Container(new BoxLayout(BoxLayout.Y_AXIS));
  42.         RadioButton topRB = new RadioButton("Top");
  43.         RadioButton LeftRB = new RadioButton("Left");
  44.         RadioButton BottomRB = new RadioButton("Bottom");
  45.         RadioButton RightRB = new RadioButton("Right");
  46.         RadioListener rbListener = new RadioListener();//自定义接收事件的类
  47.         topRB.addActionListener(rbListener);
  48.         LeftRB.addActionListener(rbListener);
  49.         BottomRB.addActionListener(rbListener);
  50.         RightRB.addActionListener(rbListener);
  51.         ButtonGroup group1 = new ButtonGroup();
  52.         group1.add(topRB);
  53.         group1.add(LeftRB);
  54.         group1.add(BottomRB);
  55.         group1.add(RightRB);
  56.         radioButtonsPanel.addComponent(new Label("Please choose a tab placement direction:"));
  57.         radioButtonsPanel.addComponent(topRB);
  58.         radioButtonsPanel.addComponent(LeftRB);
  59.         radioButtonsPanel.addComponent(BottomRB);
  60.         radioButtonsPanel.addComponent(RightRB);
  61.         tp.addTab("Tab 2", radioButtonsPanel);
  62.         //----------------------第三页的内容----------------------------------
  63.         //Container就是一个控件,只不过相当于容器,建议每页有自己的事件处理
  64.         Container TextPanel = new Container(new BoxLayout(BoxLayout.Y_AXIS));
  65.         ButtonListener txtListener = new ButtonListener();//按钮事件处理
  66.         title = new TextField("Title");   
  67.         title.getStyle().setBgTransparency(100);
  68.         body = new TextArea("This is the body of the alert...."320);
  69.         body.getStyle().setBgTransparency(100);
  70.         final Button ShowMessage =new Button("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("Tab 3", TextPanel);
  77.         form.addComponent("Center", tp);
  78.     }
  79.     /** 监听 radio buttons事件 */
  80.     class RadioListener implements ActionListener {
  81.         public void actionPerformed(ActionEvent e) {
  82.             String title = ((RadioButton) e.getSource()).getText();
  83.             Dialog.show("TabbedPaneDemo", title, "OK"null);
  84.         }
  85.     }
  86.     /** 监听 buttons事件 */
  87.     class ButtonListener implements ActionListener {
  88.         public void actionPerformed(ActionEvent e) {
  89.            Dialog.show(title.getText(), body.getText(), "OK"null);
  90.         }
  91.     }
  92.     /** 监听command事件 */
  93.     public void actionPerformed(ActionEvent arg0) {
  94.         UIDemoMIDlet.backToMainMenu();
  95.     }
  96. }


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值