Sep
23
J2ME GUI实战之七 ----------LWUIT的Tabbed分页、Text文本
首先,想让大家看看本例实现之后的动画:

首先,先来说说“分页”,Win32控件中,有种控件叫做Tab,这个功能是把一个窗体分层,同时可以容纳更多控件(注:这里的分页并不是B/S的网络数据库中的分页)。
在J2ME中实现Tab,可谓是件好事,包含Tab控件的Class可以作为主类,从而根据需求关联更多的应用。然后,使用Tab效果最好的是触摸屏手机...........
LWUIT里的Text控件,跟原来的Text控件差不多,很多人都疑惑:Text控件输入汉字时,到底是用高级的输入框,还是在当前界面输入........答案是调用高级输入框!
OK,废话少说,直接来代码,这里的代码也是修改自Sample例子:
/*
* Copyright ?2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
*/
package com.sun.lwuit.uidemo;
import com.sun.lwuit.Button;
import com.sun.lwuit.ButtonGroup;
import com.sun.lwuit.Command;
import com.sun.lwuit.Container;
import com.sun.lwuit.Dialog;
import com.sun.lwuit.Form;
import com.sun.lwuit.Label;
import com.sun.lwuit.RadioButton;
import com.sun.lwuit.TabbedPane;
import com.sun.lwuit.TextArea;
import com.sun.lwuit.TextField;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
/**
* 本例演示如何使用Tabbed、Text控件
*/
public class TabbedPaneDemo implements ActionListener {
public Form form = new Form("TabbedPaneDemo");
private Command backCommand = new Command("Back", 1);
final TextArea title ;
final TextArea body;
TabbedPane tp = null;
TabbedPaneDemo() {
form.setLayout(new BorderLayout());
form.setScrollable(false);
form.addCommand(backCommand);
form.setCommandListener(this);
tp = new TabbedPane();
//addTab可以为页面添加控件,也可以是Container(相当于容器的控件)
tp.addTab("Tab 1", new Label("Welcome to TabbedPane demo!"));
//---------------------第二页的内容------------------------------------
//Container就是一个控件,只不过相当于容器,建议每页有自己的事件处理
Container radioButtonsPanel = new Container(new BoxLayout(BoxLayout.Y_AXIS));
RadioButton topRB = new RadioButton("Top");
RadioButton LeftRB = new RadioButton("Left");
RadioButton BottomRB = new RadioButton("Bottom");
RadioButton RightRB = new RadioButton("Right");
RadioListener rbListener = new RadioListener();//自定义接收事件的类
topRB.addActionListener(rbListener);
LeftRB.addActionListener(rbListener);
BottomRB.addActionListener(rbListener);
RightRB.addActionListener(rbListener);
ButtonGroup group1 = new ButtonGroup();
group1.add(topRB);
group1.add(LeftRB);
group1.add(BottomRB);
group1.add(RightRB);
radioButtonsPanel.addComponent(new Label("Please choose a tab placement direction:"));
radioButtonsPanel.addComponent(topRB);
radioButtonsPanel.addComponent(LeftRB);
radioButtonsPanel.addComponent(BottomRB);
radioButtonsPanel.addComponent(RightRB);
tp.addTab("Tab 2", radioButtonsPanel);
//----------------------第三页的内容----------------------------------
//Container就是一个控件,只不过相当于容器,建议每页有自己的事件处理
Container TextPanel = new Container(new BoxLayout(BoxLayout.Y_AXIS));
ButtonListener txtListener = new ButtonListener();//按钮事件处理
title = new TextField("Title");
title.getStyle().setBgTransparency(100);
body = new TextArea("This is the body of the alert....", 3, 20);
body.getStyle().setBgTransparency(100);
final Button ShowMessage =new Button("ok");
ShowMessage.getStyle().setBgTransparency(100);
ShowMessage.addActionListener(txtListener);
TextPanel.addComponent(title);
TextPanel.addComponent(body);
TextPanel.addComponent(ShowMessage);
tp.addTab("Tab 3", TextPanel);
form.addComponent("Center", tp);
}
/** 监听 radio buttons事件 */
class RadioListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
String title = ((RadioButton) e.getSource()).getText();
Dialog.show("TabbedPaneDemo", title, "OK", null);
}
}
/** 监听 buttons事件 */
class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
Dialog.show(title.getText(), body.getText(), "OK", null);
}
}
/** 监听command事件 */
public void actionPerformed(ActionEvent arg0) {
UIDemoMIDlet.backToMainMenu();
}
}
本文来自:http://blog.csdn.net/hellogv/ ,转载必须注明出处!

首先,先来说说“分页”,Win32控件中,有种控件叫做Tab,这个功能是把一个窗体分层,同时可以容纳更多控件(注:这里的分页并不是B/S的网络数据库中的分页)。
在J2ME中实现Tab,可谓是件好事,包含Tab控件的Class可以作为主类,从而根据需求关联更多的应用。然后,使用Tab效果最好的是触摸屏手机...........
LWUIT里的Text控件,跟原来的Text控件差不多,很多人都疑惑:Text控件输入汉字时,到底是用高级的输入框,还是在当前界面输入........答案是调用高级输入框!
OK,废话少说,直接来代码,这里的代码也是修改自Sample例子:
/*
* Copyright ?2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
*/
package com.sun.lwuit.uidemo;
import com.sun.lwuit.Button;
import com.sun.lwuit.ButtonGroup;
import com.sun.lwuit.Command;
import com.sun.lwuit.Container;
import com.sun.lwuit.Dialog;
import com.sun.lwuit.Form;
import com.sun.lwuit.Label;
import com.sun.lwuit.RadioButton;
import com.sun.lwuit.TabbedPane;
import com.sun.lwuit.TextArea;
import com.sun.lwuit.TextField;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
/**
* 本例演示如何使用Tabbed、Text控件
*/
public class TabbedPaneDemo implements ActionListener {
public Form form = new Form("TabbedPaneDemo");
private Command backCommand = new Command("Back", 1);
final TextArea title ;
final TextArea body;
TabbedPane tp = null;
TabbedPaneDemo() {
form.setLayout(new BorderLayout());
form.setScrollable(false);
form.addCommand(backCommand);
form.setCommandListener(this);
tp = new TabbedPane();
//addTab可以为页面添加控件,也可以是Container(相当于容器的控件)
tp.addTab("Tab 1", new Label("Welcome to TabbedPane demo!"));
//---------------------第二页的内容------------------------------------
//Container就是一个控件,只不过相当于容器,建议每页有自己的事件处理
Container radioButtonsPanel = new Container(new BoxLayout(BoxLayout.Y_AXIS));
RadioButton topRB = new RadioButton("Top");
RadioButton LeftRB = new RadioButton("Left");
RadioButton BottomRB = new RadioButton("Bottom");
RadioButton RightRB = new RadioButton("Right");
RadioListener rbListener = new RadioListener();//自定义接收事件的类
topRB.addActionListener(rbListener);
LeftRB.addActionListener(rbListener);
BottomRB.addActionListener(rbListener);
RightRB.addActionListener(rbListener);
ButtonGroup group1 = new ButtonGroup();
group1.add(topRB);
group1.add(LeftRB);
group1.add(BottomRB);
group1.add(RightRB);
radioButtonsPanel.addComponent(new Label("Please choose a tab placement direction:"));
radioButtonsPanel.addComponent(topRB);
radioButtonsPanel.addComponent(LeftRB);
radioButtonsPanel.addComponent(BottomRB);
radioButtonsPanel.addComponent(RightRB);
tp.addTab("Tab 2", radioButtonsPanel);
//----------------------第三页的内容----------------------------------
//Container就是一个控件,只不过相当于容器,建议每页有自己的事件处理
Container TextPanel = new Container(new BoxLayout(BoxLayout.Y_AXIS));
ButtonListener txtListener = new ButtonListener();//按钮事件处理
title = new TextField("Title");
title.getStyle().setBgTransparency(100);
body = new TextArea("This is the body of the alert....", 3, 20);
body.getStyle().setBgTransparency(100);
final Button ShowMessage =new Button("ok");
ShowMessage.getStyle().setBgTransparency(100);
ShowMessage.addActionListener(txtListener);
TextPanel.addComponent(title);
TextPanel.addComponent(body);
TextPanel.addComponent(ShowMessage);
tp.addTab("Tab 3", TextPanel);
form.addComponent("Center", tp);
}
/** 监听 radio buttons事件 */
class RadioListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
String title = ((RadioButton) e.getSource()).getText();
Dialog.show("TabbedPaneDemo", title, "OK", null);
}
}
/** 监听 buttons事件 */
class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
Dialog.show(title.getText(), body.getText(), "OK", null);
}
}
/** 监听command事件 */
public void actionPerformed(ActionEvent arg0) {
UIDemoMIDlet.backToMainMenu();
}
}
本文来自:http://blog.csdn.net/hellogv/ ,转载必须注明出处!
J2ME GUI实战之六 ----------LWUIT的L
J2ME GUI实战之八 ----------LWUIT的



