Given a GUI app, a user will select one of the two radio buttons, JRadioButton a
, or JRadioButton b
. Depending on his selection, he will enter different inputs. However, to calculate a formula, he will click on a regular button, JButton c
.
However, the trouble ensues when more than two member functions are called within the ActionListener
.
c = new JButton( "c" ); c.addActionListener( new ActionListener() { @Override public void actionPerformed( ActionEvent e ) { cActionPerformed( e ); } });
For within the ActionEvent
, we have,
public void cActionPerformed( ActionEvent ev ) { try { double f = foo.blah( x, y ); double b = bar.meh( y, z ); } catch( NumberFormatException e ) { JOptionPane.showConfirmDialog( null, "Error message.", "Error", JOptionPane.CANCEL_OPTION ); } }
However, the program only goes down one level in the call stack, returning the catch
exception dialog. How do I make it so that when the user presses button c
, depending on whether a
or b
is selected, he gets f
or b
, respectively?
For within the ActionEvent, we have,
better would be post an SSCCE – mKorbelblah
andmeh
be evaluated for a given click? Arex
andz
mutually exclusive? Can inputs be verified on entry? – trashgod