Page 758 - Introduction to Programming with Java: A Problem Solving Approach
P. 758

                724 Chapter 17 GUI Programming—Component Layout, Additional GUI Components
 private class Listener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == standard) // standard option chosen
{
}
prior.setEnabled(false);
diskSpace.setEnabled(false);
updates.setEnabled(false);
spyware.setEnabled(false);
prior.setSelected(true);
diskSpace.setSelected(true);
updates.setSelected(false);
spyware.setSelected(false);
else // custom option chosen
{
}
prior.setEnabled(true);
diskSpace.setEnabled(true);
updates.setEnabled(true);
spyware.setEnabled(true);
// end actionPerAfoprmaedgo PDF Enhancer } // end Listener
}
Figure 17.14 Listener code for figure 17.13’s installation-options windows
to see whether the standard option was selected. If that’s the case, we disable the check boxes by call- ing setEnabled(false) for each check box. We then assign the check boxes to their standard set- tings by calling setSelected(true) or setSelected(false) for each check box. In the else block, we handle the custom option being selected. We enable the check boxes by having each box call setEnabled(true). This enables the user to control whether the box is selected or not.
17.13 JradioButton Component User Interface
Look at the circles in the windows in Figure 17.13. They’re called radio buttons. A JRadioButton com- ponent displays a small circle with a label to its right. When the circle is blank, the radio button is un- selected. When the circle contains a large dot, the radio button is selected.
According to the description so far, radio buttons sound a lot like check boxes. They display a shape and a label, and they keep track of whether something is on or off. The key difference between radio but- tons and check boxes is that radio buttons almost always come in groups. And within a radio button group, only one radio button can be selected at a time. If a user clicks an unselected radio button, the clicked but- ton becomes selected, and the previously selected button in the group becomes unselected. If a user clicks a
 




































































   756   757   758   759   760