JRadioButton class
The JRadioButton class is used to create a radio button. It is used to choose one option from multiple options. It is widely used in exam systems or quiz.
It should be added in ButtonGroup to select one radio button only.
Commonly used Constructors of JRadioButton class:
- JRadioButton(): creates an unselected radio button with no text.
- JRadioButton(String s): creates an unselected radio button with specified text.
- JRadioButton(String s, boolean selected): creates a radio button with the specified text and selected status.
Commonly used Methods of AbstractButton class:
1) public void setText(String s): is used to set specified text on button. |
2) public String getText(): is used to return the text of the button. |
3) public void setEnabled(boolean b): is used to enable or disable the button. |
4) public void setIcon(Icon b): is used to set the specified Icon on the button. |
5) public Icon getIcon(): is used to get the Icon of the button. |
6) public void setMnemonic(int a): is used to set the mnemonic on the button. |
7) public void addActionListener(ActionListener a): is used to add the action listener to this object. |
Note: The JRadioButton class extends the JToggleButton class that extends AbstractButton class.
Example of JRadioButton class:
ButtonGroup class:
The ButtonGroup class can be used to group multiple buttons so that at a time only one button can be selected. |
No comments:
Post a Comment