FileDocCategorySizeDatePackage
CheckBoxDemo.javaAPI DocExample4414Tue Dec 12 18:59:16 GMT 2000None

CheckBoxDemo

public class CheckBoxDemo extends JPanel

Fields Summary
JCheckBox
chinButton
JCheckBox
glassesButton
JCheckBox
hairButton
JCheckBox
teethButton
StringBuffer
choices
JLabel
pictureLabel
Constructors Summary
public CheckBoxDemo()


        // Create the check boxes
        chinButton = new JCheckBox("Chin");
        chinButton.setMnemonic(KeyEvent.VK_C); 
        chinButton.setSelected(true);

        glassesButton = new JCheckBox("Glasses");
        glassesButton.setMnemonic(KeyEvent.VK_G); 
        glassesButton.setSelected(true);

        hairButton = new JCheckBox("Hair");
        hairButton.setMnemonic(KeyEvent.VK_H); 
        hairButton.setSelected(true);

        teethButton = new JCheckBox("Teeth");
        teethButton.setMnemonic(KeyEvent.VK_T); 
        teethButton.setSelected(true);

        // Register a listener for the check boxes.
        CheckBoxListener myListener = new CheckBoxListener();
        chinButton.addItemListener(myListener);
        glassesButton.addItemListener(myListener);
        hairButton.addItemListener(myListener);
        teethButton.addItemListener(myListener);

        // Indicates what's on the geek.
        choices = new StringBuffer("cght");

        // Set up the picture label
        pictureLabel = new JLabel(new ImageIcon(
                                        "images/geek/geek-" 
                                         + choices.toString()
                                         + ".gif"));
        pictureLabel.setToolTipText(choices.toString());

        // Put the check boxes in a column in a panel
        JPanel checkPanel = new JPanel();
        checkPanel.setLayout(new GridLayout(0, 1));
        checkPanel.add(chinButton);
        checkPanel.add(glassesButton);
        checkPanel.add(hairButton);
        checkPanel.add(teethButton);

        setLayout(new BorderLayout());
        add(checkPanel, BorderLayout.WEST);
        add(pictureLabel, BorderLayout.CENTER);
        setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
    
Methods Summary
public static voidmain(java.lang.String[] s)

         JFrame frame = new JFrame("CheckBoxDemo");
         frame.addWindowListener(new WindowAdapter() {
             public void windowClosing(WindowEvent e) {
                 System.exit(0);
             }
         });
 
         frame.setContentPane(new CheckBoxDemo());
         frame.pack();
         frame.setVisible(true);