The files StyleOptions.java and StyleOptionsPanel.java are from Listings 5.22 and 5.23 of the text (Java Software Solutions 6th Edition - Lewis & Loftus - with a couple of slight changes-an instance variable fontSize is used rather than the literal 36 for font size and the variable style is an instance variable rather than local to the itemStateChanged method). The program demonstrates checkboxes and ItemListeners. In this exercise you will add a set of three radio buttons to let the user choose among three font sizes. The method of adding the radio buttons will be very similar to that in the QuoteOptionsPanel class (Listing 5.25 of the text). Before modifying the program compile and run the current version to see how it works and study the QuoteOptionsPanel example.
Do the following to add the radio buttons to the panel:
1. Declare three objects small, medium, and large of type JRadioButton.
2. Instantiate the button objects labeling them "Small Font," "Medium Font," "Large Font." Initialize the large font button to true. Set the background color of the buttons to cyan.
3. Instantiate a button group object and add the buttons to it.
4. Radio buttons produce action events so you need an ActionListener to listen for radio button clicks. The code you need to add to actionPerformed will be similar to that in the QuoteListener in Listing 5.25. In this case you need to set the fontSize variable (use 12 for small, 24 for medium, and 36 for large) in the if statement, then call the setFont method to set the font for the saying object. (Note: Instead of adding an ActionListener you could use the current ItemListener and add code to check to see if the source of the event was a radio button.)
5. In StyleOptionsPanel() add the ItemListener object to each button and add each button to the panel.
6. Compile and run the program. Note that as the font size changes the checkboxes and buttons re-arrange themselves in the panel. You will learn how to control layout later in the course.