I am creating a GUI in which you first click on a radio button to define a variable, and then you click on a button. This button then tests for that variable and then performs two different actions depending on what the integer equals. My problem is that, when I click on the button, the variable which is defined with the radio buttons is not registered. I need to make this variable be able to be found by the action listener which the button takes advantage of. Here is a segment of my code:
radioButtonYes.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
int a = 1;
}
});
radioButtonNo.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
int a = 2;
}
});
submitOne.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(a == 1){
frame.setVisible(false);
JPanel panelFour = new JPanel();
JLabel labelTwo = new JLabel("Stuff");
panelFour.add(labelTwo);
frame.remove(panelOne);
frame.remove(panelTwo);
frame.remove(submitOne);
frame.add(panelFour);
frame.setVisible(true);
}else{
frame.setVisible(false);
JPanel panelFive = new JPanel();
JLabel labelThree = new JLabel("Alternate stuff");
panelFive.add(labelThree);
frame.remove(panelOne);
frame.remove(panelTwo);
frame.remove(submitOne);
frame.add(panelFive);
frame.setVisible(true);
}
}
});