//********************************************************************
// StyleGUI.java Author: Lewis/Loftus
//
// Represents the user interface for the StyleOptions program.
//********************************************************************
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class StyleGUI
{
private final int WIDTH = 350, HEIGHT = 100, FONT_SIZE = 14;
private JLabel prompt;
private JTextField quote;
private JCheckBox bold, italic;
private JPanel primary;
//-----------------------------------------------------------------
// Sets up a panel with a label and some check boxes that
// control the style of the label's font.
//-----------------------------------------------------------------
public StyleGUI()
{
prompt = new JLabel("Enter your favorite quote:");
quote = new JTextField("Your quote here", 30);
quote.setEditable(true);
quote.setFont (new Font ("Helvetica", Font.PLAIN, FONT_SIZE));
bold = new JCheckBox ("Bold");
bold.setBackground (Color.cyan);
italic = new JCheckBox ("Italic");
italic.setBackground (Color.cyan);
StyleListener listener = new StyleListener();
bold.addItemListener (listener);
italic.addItemListener (listener);
primary = new JPanel();
primary.add (prompt);
primary.add (quote);
primary.add (bold);
primary.add (italic);
primary.setBackground (Color.cyan);
primary.setPreferredSize (new Dimension(WIDTH, HEIGHT));
}
//-----------------------------------------------------------------
// Returns the primary panel containing the GUI.
//-----------------------------------------------------------------
public JPanel getPanel()
{
return primary;
}
private class TextFieldHandler implements ActionListener
{
//--------------------------------------------------------------
// Updates the style of the label font style.
//--------------------------------------------------------------
public void actionPerformed(ActionEvent event)
{

}
}
//*****************************************************************
// Represents the listener for both check boxes.
//*****************************************************************
private class StyleListener implements ItemListener
{
//--------------------------------------------------------------
// Updates the style of the label font style.
//--------------------------------------------------------------
public void itemStateChanged (ItemEvent event)
{
int style = Font.PLAIN;
if (bold.isSelected())
style = Font.BOLD;
if (italic.isSelected())
style += Font.ITALIC;
quote.setFont (new Font ("Helvetica", style, FONT_SIZE));
}
}
}