You need to recalculate the value for menuSelection
when the 'OK' button is clicked; you're setting it once during instantiation of the Choice
as shown below:
final int menuSelection = cMenu.getSelectedIndex();
If you do something like this, you should be able to see your value:
OK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int currentSelection = cMenu.getSelectedIndex();
System.out.println(currentSelection);
}
});
This will mean cMenu
should be final, which is probably OK because you don't need to ever update that reference.