JRadioButton
Java Swing Tutorial Explaining the JRadioButton Component. JRadioButton is similar to JCheckbox, except for the default icon for each class. A set of radio buttons can be associated as a group in which only one button at a time can be selected.
JRadioButton Source Code
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JRadioButtonDemo extends JPanel {
static JFrame frame;
JLabel jlbPicture;
RadioListener myListener = null;
public JRadioButtonDemo() {
// Create the radio buttons and assign Keyboard shortcuts using
// Mnemonics
JRadioButton jrbNumbers = new JRadioButton("Numbers");
jrbNumbers.setMnemonic(KeyEvent.VK_N);
jrbNumbers.setActionCommand("numbers");
jrbNumbers.setSelected(true);
JRadioButton jrbAlphabets = new JRadioButton("Alphabets");
jrbAlphabets.setMnemonic(KeyEvent.VK_A);
jrbAlphabets.setActionCommand("alphabets");
JRadioButton jrbSymbols = new JRadioButton("Symbols");
jrbSymbols.setMnemonic(KeyEvent.VK_S);
jrbSymbols.setActionCommand("symbols");
// Group the radio buttons.
ButtonGroup group = new ButtonGroup();
group.add(jrbNumbers);
group.add(jrbAlphabets);
group.add(jrbSymbols);
// Register an action listener for the radio buttons.
myListener = new RadioListener();
jrbNumbers.addActionListener(myListener);
|
Output
Download jRadioButton Source Code
Java JRadioButton Hierarchy
javax.swing
Class JRadioButton
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.AbstractButton
javax.swing.JToggleButton
javax.swing.JRadioButton
All Implemented Interfaces:
Accessible, ImageObserver, ItemSelectable, MenuContainer, Serializable, SwingConstants
Class JRadioButton
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.AbstractButton
javax.swing.JToggleButton
javax.swing.JRadioButton
All Implemented Interfaces:
Accessible, ImageObserver, ItemSelectable, MenuContainer, Serializable, SwingConstants
JRadioButton Constructor
JRadioButton()
Creates an initially unselected radio button with no set text.
Creates an initially unselected radio button with no set text.
JRadioButton(Action a)
Creates a radiobutton where properties are taken from the Action supplied.
Creates a radiobutton where properties are taken from the Action supplied.
JRadioButton(Icon icon)
Creates an initially unselected radio button with the specified image but no text.
Creates an initially unselected radio button with the specified image but no text.
JRadioButton(Icon icon, boolean selected)
Creates a radio button with the specified image and selection state, but no text.
Creates a radio button with the specified image and selection state, but no text.
JRadioButton(String text)
Creates an unselected radio button with the specified text.
Creates an unselected radio button with the specified text.
JRadioButton(String text, boolean selected)
Creates a radio button with the specified text and selection state.
Creates a radio button with the specified text and selection state.
JRadioButton(String text, Icon icon)
Creates a radio button that has the specified text and image, and that is initially unselected.
Creates a radio button that has the specified text and image, and that is initially unselected.
JRadioButton(String text, Icon icon, boolean selected)
Creates a radio button that has the specified text, image, and selection state.
Creates a radio button that has the specified text, image, and selection state.
0 comments:
Post a Comment