AWT CheckBoxGroup类
介绍
checkboxgroup类用于分组组复选框。
类的声明
以下是声明为java.awt.CheckboxGroup类:
public class CheckboxGroup extends Object implements Serializable
类的构造函数
S.N. | 构造函数与说明 |
---|---|
1 |
CheckboxGroup() () Creates a new instance of CheckboxGroup. |
类方法
S.N. | 方法和说明 |
---|---|
1 |
Checkbox getCurrent() Deprecated. As of JDK version 1.1, replaced by getSelectedCheckbox(). |
2 |
Checkbox getSelectedCheckbox() Gets the current choice from this check box group. |
3 |
void setCurrent(Checkbox box) Deprecated. As of JDK version 1.1, replaced by setSelectedCheckbox(Checkbox). |
4 |
void setSelectedCheckbox(Checkbox box) Sets the currently selected check box in this group to be the specified check box. |
5 |
String toString() Returns a string representation of this check box group, including the value of its current selection. |
继承的方法
这个类继承的方法从以下类:
-
java.lang.Object
checkboxgroup的实例
选择使用编辑器创建以下java程序D:/ > AWT > com > gitbook.net > gui >
AwtControlDemo.javapackage com.yiibai.gui; import java.awt.*; import java.awt.event.*; public class AwtControlDemo { private Frame mainFrame; private Label headerLabel; private Label statusLabel; private Panel controlPanel; public AwtControlDemo(){ prepareGUI(); } public static void main(String[] args){ AwtControlDemo awtControlDemo = new AwtControlDemo(); awtControlDemo.showCheckBoxGroupDemo(); } private void prepareGUI(){ mainFrame = new Frame("Java AWT Examples"); mainFrame.setSize(400,400); mainFrame.setLayout(new GridLayout(3, 1)); mainFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent windowEvent){ System.exit(0); } }); headerLabel = new Label(); headerLabel.setAlignment(Label.CENTER); statusLabel = new Label(); statusLabel.setAlignment(Label.CENTER); statusLabel.setSize(350,100); controlPanel = new Panel(); controlPanel.setLayout(new FlowLayout()); mainFrame.add(headerLabel); mainFrame.add(controlPanel); mainFrame.add(statusLabel); mainFrame.setVisible(true); } private void showCheckBoxGroupDemo(){ headerLabel.setText("Control in action: CheckBoxGroup"); CheckboxGroup fruitGroup = new CheckboxGroup(); Checkbox chkApple = new Checkbox("Apple",fruitGroup,true); Checkbox chkMango = new Checkbox("Mango",fruitGroup,false); Checkbox chkPeer = new Checkbox("Peer",fruitGroup,false); statusLabel.setText("Apple Checkbox: checked"); chkApple.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { statusLabel.setText("Apple Checkbox: checked"); } }); chkMango.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { statusLabel.setText("Mango Checkbox: checked"); } }); chkPeer.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { statusLabel.setText("Peer Checkbox: checked"); } }); controlPanel.add(chkApple); controlPanel.add(chkMango); controlPanel.add(chkPeer); mainFrame.setVisible(true); } }
编译程序,使用命令提示符。到D:/ > AWT 然后键入以下命令。
D:AWT>javac comyiibaiguiAwtControlDemo.java
如果没有错误出现,这意味着编译成功。使用下面的命令来运行程序。
D:AWT>java com.yiibai.gui.AwtControlDemo
验证下面的输出