//   Author: Brian C. Hoffman
//     File: CBoxApplet.java
// Abstract: In order to demonstrate event handeling with checkboxex this applet
//            displays text together with a checkbox for making that text bold. 
//                  
//  Revision History:      	Date (Due Date)	   Who	 Description
// -----------------------------------------------------------------------------
//		                    2/12/03            BCH	 Initial Release
//
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class CBoxApplet extends JApplet
{
    JCheckBox boldCheck;
    int fontStyle;
    
    // initialize the applet and create the GUI
    public void init()
    {
        // set the size of the applet
        setSize(400, 200);
        
        // create the check box and add an ItemListener to it
        boldCheck = new JCheckBox("Bold");
        boldCheck.addItemListener(new myBoxListener());
      
        // add everything to the applet
        Container container = getContentPane();
        container.add(boldCheck, BorderLayout.SOUTH);
    }
    
    // draw graphics 
    public void paint(Graphics g)
    {
        super.paint(g);
        g.setFont(new Font("SanSarif", fontStyle, 32));
        g.drawString("Java Applets are Cool", 10, 100); 
    }
    
    // event handler
    private class myBoxListener implements ItemListener
    {
        int valBold;
        public void itemStateChanged(ItemEvent event)
        {
            if (event.getSource() == boldCheck)
            {
               if (event.getStateChange() == ItemEvent.SELECTED)   
                  valBold = Font.BOLD;
               else
                  valBold = Font.PLAIN;
            }
            fontStyle = valBold;
            repaint();
        }
    }// end myBoxListener
}// end CBoxApplet


