⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rb_cb_lb.java

📁 J2ME lwuit实现屏幕九宫图,功能十分强大
💻 JAVA
字号:
/* * Copyright ?2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */package com.sun.lwuit.uidemo;import com.sun.lwuit.ButtonGroup;import com.sun.lwuit.CheckBox;import com.sun.lwuit.Command;import com.sun.lwuit.Component;import com.sun.lwuit.Dialog;import com.sun.lwuit.Form;import com.sun.lwuit.Label;import com.sun.lwuit.RadioButton;import com.sun.lwuit.layouts.BoxLayout;import com.sun.lwuit.events.ActionEvent;import com.sun.lwuit.events.ActionListener;/** * 演示RadioButton、CheckBox、Label的使用 */public class Rb_Cb_Lb implements ActionListener {public Form form = new Form("Rb_Cb_Lb");public  Command backCommand = new Command("Back", 1);//返回按钮public  Command selectCommand = new Command("select", 2);//确认选择的按钮//ButtonGroup就是把所有的RadioButton放在一起,选择唯一public ButtonGroup group = new ButtonGroup();    Rb_Cb_Lb(){        form.setLayout(new BoxLayout(BoxLayout.Y_AXIS));        form.addCommand(backCommand);        form.addCommand(selectCommand);        form.setCommandListener(this);        Label cdlabel = new Label("CheckBox:");        cdlabel.getStyle().setMargin(Component.BOTTOM, 0);        form.addComponent(cdlabel);        final CheckBox firstCB = new CheckBox("First CheckBox");        firstCB.getStyle().setMargin(Component.TOP, 1);        form.addComponent(firstCB);        final CheckBox secondCB = new CheckBox("Second CheckBox");        secondCB.getStyle().setMargin(0, 5, 2, 2);        form.addComponent(secondCB);        Label rblabel = new Label("RadioButton:");        rblabel.getStyle().setMargin(Component.BOTTOM, 0);        form.addComponent(rblabel);        final RadioButton firstRB = new RadioButton("First RadioButton");        form.addComponent(firstRB);                final RadioButton secondRB = new RadioButton("Second RadioButton");        form.addComponent(secondRB);        final RadioButton thirdRB = new RadioButton("Third RadioButton");        form.addComponent(thirdRB);        ActionListener listener = new ActionListener() {        //这里是处理CheckBox、RadioButton 点击事件处理程序            public void actionPerformed(ActionEvent arg0) {                Object source = arg0.getSource();                if(source==firstCB)                    Dialog.show("Rb_Cb_Lb","firstCB", "OK", null);                else if(source==secondCB)                    Dialog.show("Rb_Cb_Lb","secondCB", "OK", null);                else if(source==firstRB)                    Dialog.show("Rb_Cb_Lb","firstRB", "OK", null);                else if(source==secondRB)                    Dialog.show("Rb_Cb_Lb","secondRB", "OK", null);                else if(source==thirdRB)                    Dialog.show("Rb_Cb_Lb","thirdRB", "OK", null);            }        };        //往ButtonGroup加入radiobutton        group.add(firstRB);        group.add(secondRB);        group.add(thirdRB);        firstRB.addActionListener(listener);//加入事件监听        secondRB.addActionListener(listener);//加入事件监听        thirdRB.addActionListener(listener);//加入事件监听//----为复选框加入事件监听        firstCB.addActionListener(listener);        secondCB.addActionListener(listener);    };    public void actionPerformed(ActionEvent arg0) {    //这里处理Command 以及 判断ButtonGroup所选中的RadioButton        Command cmd=arg0.getCommand();        if(cmd==backCommand)            UIDemoMIDlet.backToMainMenu();        else if(cmd==selectCommand)        {            String str="ButtonCount:"+group.getButtonCount()+'\n'+                       "SelectedIndex:"+group.getSelectedIndex()+'\n'+                       "RadioButton:"+(group.getRadioButton(group.getSelectedIndex()).getText());            Dialog.show("Rb_Cb_Lb",str, "OK", null);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -