QuoteGUI

QuoteGUI - group.add(carpentry QuoteListener listener = new QuoteListener comedy.addActionListener(listener philosophy.addActionListener(listener

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 // QuoteGUI.java // Represents the user interface for the QuoteOptions // program. 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)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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) { Sheet1 Page 2 Object source = event.getSource() if (source == comedy) quote.setText (comedyQuote) else if (source == philosophy) quote.setText (philosophyQuote) else quote.setText (carpentryQuote) } } // end of QuoteListener class } // end of QuoteGUI class...
View Full Document

This note was uploaded on 06/11/2009 for the course CS 205214 taught by Professor Balasooriya/kouvetakis during the Spring '09 term at ASU.

Page1 / 2

QuoteGUI - group.add(carpentry QuoteListener listener = new QuoteListener comedy.addActionListener(listener philosophy.addActionListener(listener

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online