The Checkboxgroup Class Is Used To Group The Set of Checkbox
The Checkboxgroup Class Is Used To Group The Set of Checkbox
Class declaration
Following is the declaration for java.awt.CheckboxGroup class:
public class CheckboxGroup
extends Object
implements Serializable
Class constructors
S.N. Constructor & Description
1
CheckboxGroup() ()
Creates a new instance of CheckboxGroup.
Class methods
S.N. Method & Description
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.
Methods inherited
This class inherits methods from the following classes:
java.lang.Object
CheckBoxGroup Example
Create the following java program using any editor of your choice in say D:/ > AWT >
com > tutorialspoint > gui >
AwtControlDemo.java
package com.tutorialspoint.gui;
import java.awt.*;
import java.awt.event.*;
public AwtControlDemo(){
prepareGUI();
}
mainFrame.add(headerLabel);
mainFrame.add(controlPanel);
mainFrame.add(statusLabel);
mainFrame.setVisible(true);
}
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);
}
}
Compile the program using command prompt. Go to D:/ > AWT and type the following
command.
D:\AWT>javac com\tutorialspoint\gui\AwtControlDemo.java
If no error comes that means compilation is successful. Run the program using following
command.
D:\AWT>java com.tutorialspoint.gui.AwtControlDemo
Verify the following output