My issue is that I do not know how to check whether or not a radio button is selected, and then choose a different output according to which one i selected. Basically, as my code is right now, once a radiobutton is selected, it is selected forever, it seems. how do i fix my code to send a different output according to what button is selected? Here is my code...
JRadioButton radioButton1;
JRadioButton radioButton2;
JRadioButton radioButton3;
JRadioButton radioButton4;
int button = 1;
....
private void createCourses(){
JPanel eastPanel = new JPanel(new GridLayout(5, 1, 10, 10));
eastPanel.setBounds(250, 50, 150, 120);
eastPanel.setBorder(raisedetched);
ButtonGroup radio = new ButtonGroup();
JLabel label1 = new JLabel("Course offerings");
radioButton1 = new JRadioButton();
radioButton2 = new JRadioButton();
radioButton3 = new JRadioButton();
radioButton4 = new JRadioButton();
eastPanel.add(label1);
eastPanel.add(radioButton1);
eastPanel.add(radioButton2);
eastPanel.add(radioButton3);
eastPanel.add(radioButton4);
radio.add(radioButton1);
radio.add(radioButton2);
radio.add(radioButton3);
radio.add(radioButton4);
radioButton1.addItemListener(this);
radioButton2.addItemListener(this);
radioButton3.addItemListener(this);
radioButton4.addItemListener(this);
radioButton1.setSelected(true);
radio.getSelection();
contentPane.add(eastPanel);
setVisible(true);
}
public void itemStateChanged(ItemEvent e) {
if(radioButton1.isSelected() == true){
button = 1;
myStats.setCourseOfferings(button);
}
else{
radioButton1.setSelected(false);
}
if(radioButton2.isSelected() == true){
button = 2;
myStats.setCourseOfferings(button);
}
if(radioButton3.isSelected() == true){
button = 3;
myStats.setCourseOfferings(button);
}
if(radioButton4.isSelected() == true){
button = 4;
myStats.setCourseOfferings(button);
}
}
}
Thank you and any help is appreciated.