//******************************************************************** // ButtonPanel.java Author: Lewis and Loftus / Peter DePasquale // // Refinement #1 // // Represents the primary panel of controls for PaintBox. //******************************************************************** import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ButtonPanel extends JPanel { private JRadioButton selectButton, lineButton, ovalButton; private JRadioButton rectButton, polyButton, colorButton; private JPanel strokeIndicator; //----------------------------------------------------------------- // Sets up the panel of buttons. //----------------------------------------------------------------- public ButtonPanel () { setLayout (new BoxLayout (this, BoxLayout.Y_AXIS)); ButtonListener listener = new ButtonListener(); ButtonGroup shapeGroup = new ButtonGroup(); selectButton = new JRadioButton (new ImageIcon("select.gif")); selectButton.addActionListener (listener); selectButton.setAlignmentX (Component.CENTER_ALIGNMENT); lineButton = new JRadioButton (new ImageIcon ("line.gif")); lineButton.addActionListener (listener); lineButton.setAlignmentX (Component.CENTER_ALIGNMENT); ovalButton = new JRadioButton (new ImageIcon ("oval.gif")); ovalButton.addActionListener (listener); ovalButton.setAlignmentX (Component.CENTER_ALIGNMENT); rectButton = new JRadioButton (new ImageIcon ("rect.gif")); rectButton.addActionListener (listener); rectButton.setAlignmentX (Component.CENTER_ALIGNMENT); polyButton = new JRadioButton (new ImageIcon ("poly.gif")); polyButton.addActionListener (listener); polyButton.setAlignmentX (Component.CENTER_ALIGNMENT); colorButton = new JRadioButton (new ImageIcon("color.gif")); colorButton.addActionListener (listener); colorButton.setAlignmentX (Component.CENTER_ALIGNMENT); shapeGroup.add (selectButton); shapeGroup.add (lineButton); shapeGroup.add (ovalButton); shapeGroup.add (rectButton); shapeGroup.add (polyButton); shapeGroup.add (colorButton); strokeIndicator = new JPanel(); strokeIndicator.setMaximumSize (new Dimension(20, 10)); strokeIndicator.setAlignmentX (Component.CENTER_ALIGNMENT); strokeIndicator.setBackground (Color.black); add (selectButton); add (Box.createRigidArea (new Dimension(1,10))); add (lineButton); add (ovalButton); add (rectButton); add (polyButton); add (Box.createRigidArea (new Dimension(1,10))); add (colorButton); add (strokeIndicator); } //***************************************************************** // An inner class to handle button events. //***************************************************************** private class ButtonListener implements ActionListener { //-------------------------------------------------------------- // Responds to action events caused by buttons. //-------------------------------------------------------------- public void actionPerformed (ActionEvent event) { // to be implemented } } }