" If you have a group of radio buttons, you know that only one of them is selected. It
would be nice to be able to quickly find out which one without having to query all the but-
tons in the group. Because the ButtonGroup object controls all buttons, it would be conve-
nient if this object could give us a reference to the selected button. Indeed, the ButtonGroup class has a getSelection method, but that method doesn’t return the radio button that is
selected. Instead, it returns a ButtonModel reference to the model attached to the button.
Unfortunately, none of the ButtonModel methods are very helpful. The ButtonModel interface
inherits a method getSelectedObjects from the ItemSelectable interface that, rather uselessly,
returns null. The getActionCommand method looks promising because the “action command”
of a radio button is its text label. But the action command of its model is null.
Only if you explicitly set the action commands of all radio buttons with the setActionCommand method do
the models’ action command values also get set. Then you can retrieve the action command
of the currently selected button with buttonGroup.getSelection().getActionCommand()"
Core Java Volume I (8th Edition) P.389
How would you adapt the following code snippet to read the action command, and, switch between different options?