本文来自:http://blog.csdn.net/hellogv/ ,转载必须注明出处!
首先,想让大家看看本例实现之后的动画:
首先,先来说说“分页”,Win32控件中,有种控件叫做Tab,这个功能是把一个窗体分层,同时可以容纳更多控件(注:这里的分页并不是B/S的网络数据库中的分页)。
在J2ME中实现Tab,可谓是件好事,包含Tab控件的Class可以作为主类,从而根据需求关联更多的应用。然后,使用Tab效果最好的是触摸屏手机...........
LWUIT里的Text控件,跟原来的Text控件差不多,很多人都疑惑:Text控件输入汉字时,到底是用高级的输入框,还是在当前界面输入........答案是调用高级输入框!
OK,废话少说,直接来代码,这里的代码也是修改自Sample例子:
首先,想让大家看看本例实现之后的动画:
首先,先来说说“分页”,Win32控件中,有种控件叫做Tab,这个功能是把一个窗体分层,同时可以容纳更多控件(注:这里的分页并不是B/S的网络数据库中的分页)。
在J2ME中实现Tab,可谓是件好事,包含Tab控件的Class可以作为主类,从而根据需求关联更多的应用。然后,使用Tab效果最好的是触摸屏手机...........
LWUIT里的Text控件,跟原来的Text控件差不多,很多人都疑惑:Text控件输入汉字时,到底是用高级的输入框,还是在当前界面输入........答案是调用高级输入框!
OK,废话少说,直接来代码,这里的代码也是修改自Sample例子:
- /*
- *Copyright?2008SunMicrosystems,Inc.Allrightsreserved.
- *Useissubjecttolicenseterms.
- *
- */
- packagecom.sun.lwuit.uidemo;
- importcom.sun.lwuit.Button;
- importcom.sun.lwuit.ButtonGroup;
- importcom.sun.lwuit.Command;
- importcom.sun.lwuit.Container;
- importcom.sun.lwuit.Dialog;
- importcom.sun.lwuit.Form;
- importcom.sun.lwuit.Label;
- importcom.sun.lwuit.RadioButton;
- importcom.sun.lwuit.TabbedPane;
- importcom.sun.lwuit.TextArea;
- importcom.sun.lwuit.TextField;
- importcom.sun.lwuit.events.ActionEvent;
- importcom.sun.lwuit.events.ActionListener;
- importcom.sun.lwuit.layouts.BorderLayout;
- importcom.sun.lwuit.layouts.BoxLayout;
- /**
- *本例演示如何使用Tabbed、Text控件
- */
- publicclassTabbedPaneDemoimplementsActionListener{
- publicFormform=newForm("TabbedPaneDemo");
- privateCommandbackCommand=newCommand("Back",1);
- finalTextAreatitle;
- finalTextAreabody;
- TabbedPanetp=null;
- TabbedPaneDemo(){
- form.setLayout(newBorderLayout());
- form.setScrollable(false);
- form.addCommand(backCommand);
- form.setCommandListener(this);
- tp=newTabbedPane();
- //addTab可以为页面添加控件,也可以是Container(相当于容器的控件)
- tp.addTab("Tab1",newLabel("WelcometoTabbedPanedemo!"));
- //---------------------第二页的内容------------------------------------
- //Container就是一个控件,只不过相当于容器,建议每页有自己的事件处理
- ContainerradioButtonsPanel=newContainer(newBoxLayout(BoxLayout.Y_AXIS));
- RadioButtontopRB=newRadioButton("Top");
- RadioButtonLeftRB=newRadioButton("Left");
- RadioButtonBottomRB=newRadioButton("Bottom");
- RadioButtonRightRB=newRadioButton("Right");
- RadioListenerrbListener=newRadioListener();//自定义接收事件的类
- topRB.addActionListener(rbListener);
- LeftRB.addActionListener(rbListener);
- BottomRB.addActionListener(rbListener);
- RightRB.addActionListener(rbListener);
- ButtonGroupgroup1=newButtonGroup();
- group1.add(topRB);
- group1.add(LeftRB);
- group1.add(BottomRB);
- group1.add(RightRB);
- radioButtonsPanel.addComponent(newLabel("Pleasechooseatabplacementdirection:"));
- radioButtonsPanel.addComponent(topRB);
- radioButtonsPanel.addComponent(LeftRB);
- radioButtonsPanel.addComponent(BottomRB);
- radioButtonsPanel.addComponent(RightRB);
- tp.addTab("Tab2",radioButtonsPanel);
- //----------------------第三页的内容----------------------------------
- //Container就是一个控件,只不过相当于容器,建议每页有自己的事件处理
- ContainerTextPanel=newContainer(newBoxLayout(BoxLayout.Y_AXIS));
- ButtonListenertxtListener=newButtonListener();//按钮事件处理
- title=newTextField("Title");
- title.getStyle().setBgTransparency(100);
- body=newTextArea("Thisisthebodyofthealert....",3,20);
- body.getStyle().setBgTransparency(100);
- finalButtonShowMessage=newButton("ok");
- ShowMessage.getStyle().setBgTransparency(100);
- ShowMessage.addActionListener(txtListener);
- TextPanel.addComponent(title);
- TextPanel.addComponent(body);
- TextPanel.addComponent(ShowMessage);
- tp.addTab("Tab3",TextPanel);
- form.addComponent("Center",tp);
- }
- /**监听radiobuttons事件*/
- classRadioListenerimplementsActionListener{
- publicvoidactionPerformed(ActionEvente){
- Stringtitle=((RadioButton)e.getSource()).getText();
- Dialog.show("TabbedPaneDemo",title,"OK",null);
- }
- }
- /**监听buttons事件*/
- classButtonListenerimplementsActionListener{
- publicvoidactionPerformed(ActionEvente){
- Dialog.show(title.getText(),body.getText(),"OK",null);
- }
- }
- /**监听command事件*/
- publicvoidactionPerformed(ActionEventarg0){
- UIDemoMIDlet.backToMainMenu();
- }
- }