Головна‎ > ‎Java Swing‎ > ‎

Чи вибрана радіокнопка Swing

rb1=new JRadioButton("Male");
rb1.setBounds(100,50,100,30);
rb2=new JRadioButton("Female");
rb2.setBounds(100,100,100,30);
ButtonGroup bg=new ButtonGroup();
bg.add(rb1);
bg.add(rb2); 
 
if(rb1.isSelected()){
JOptionPane.showMessageDialog(this,"You are Male.");
 
if(rb2.isSelected()){
JOptionPane.showMessageDialog(this,"You are Female.");
}