Java Reference
In-Depth Information
JButton button = new JButton ("Order Pizza");
button.addActionListener(buttonActionListener);
frame.add(sliceContainer, BorderLayout.WEST);
frame.add(crustContainer, BorderLayout.EAST);
frame.add(button, BorderLayout.SOUTH);
frame.setSize(300, 200);
frame.setVisible(true);
}
};
EventQueue.invokeLater(runner);
}
}
Figure 5-12.
The GroupActionRadio program sample screen
A few more changes were made to the
RadioButtonUtils
class to deal with registering
ChangeListener
objects to all the radio buttons in a
ButtonGroup
. The complete and final class
definition is shown in Listing 5-8.
Listing 5-8.
Complete Support Class for Working with JRadioButton
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Enumeration;
import java.util.Vector;
public class RadioButtonUtils {
private RadioButtonUtils() {
// Private constructor so you can't create instances
}