Sheet1
Page 1
import javax.swing.*
import java.awt.*
import java.awt.event.*
public class QuoteGUI extends JPanel
{
private JLabel quote
private JRadioButton comedy, philosophy, carpentry
private String comedyQuote = "Take my wife, please."
private String philosophyQuote = "I think, therefore I am."
private String carpentryQuote = "Measure twice. Cut once."
// Sets up a panel with a label and a set of radio buttons
// that control its text.
public QuoteGUI()
{
quote = new JLabel (comedyQuote)
quote.setFont (new Font ("Helvetica", Font.BOLD, 24))
comedy = new JRadioButton ("Comedy", true)
philosophy = new JRadioButton ("Philosophy")
carpentry = new JRadioButton ("Carpentry")
ButtonGroup group = new ButtonGroup() //in swing
group.add (comedy)
group.add (philosophy)
group.add (carpentry)
QuoteListener listener = new QuoteListener()
comedy.addActionListener (listener)
philosophy.addActionListener (listener)
carpentry.addActionListener (listener)
add (quote)
add (comedy)
add (philosophy)
add (carpentry)
} // end of constructor of QuoteGUI
// QuoteListener represents the listener for
// all radio buttons
private class QuoteListener implements ActionListener
{
// Sets the text of the label depending on which
// radio button was pressed.
public void actionPerformed (ActionEvent event)
{
// QuoteGUI.java
// Represents the user interface for the QuoteOptions
// program.