Create a JRadioButton Component in Java
import javax.swing.*;
import java.awt.*;
public class RadioButtonr {
public RadioButton() {
JRadioButton Male, Female;
JFrame frame = new JFrame("Creating a JRadioButton Component");
JPanel panel = new JPanel();
ButtonGroup buttonGroup = new ButtonGroup();
Male = new JRadioButton("Male");
buttonGroup.add(Male);
panel.add(Male);
Female = new JRadioButton("Female");
buttonGroup.add(Female);
panel.add(Female);
Male.setSelected(true);
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 400);
frame.setVisible(true);
}
public static void main(String[] args) {
RadioButton r = new RadioButton();
}
}
0 comments:
Post a Comment