import java.awt.*; import java.awt.event.*; import javax.swing.*; public class VoteCounterPanel extends JPanel { private int votesForBlue; private JLabel labelBlue; private JButton blue; // ------------------------------------------------------------ // Sets up the GUI // ------------------------------------------------------------ public VoteCounterPanel () { votesForBlue = 0; blue = new JButton ("Vote for Blue!"); VoteButtonListener voteListener = new VoteButtonListener(); blue.addActionListener (voteListener); labelBlue = new JLabel ("Votes for Blue: " + votesForBlue); add (blue); add (labelBlue); setBackground (Color.white); } // ******************************************************************* // Represents a listener for button push actions // ******************************************************************* private class VoteButtonListener implements ActionListener { public void actionPerformed (ActionEvent event) { votesForBlue++; labelBlue.setText ("Votes for Blue: " + votesForBlue); } } }Suppose we wanted to add a second button to the panel, one for candidate Red. We would need three new instance variables - a vote counter for Red, a button, and a label. Add code to the above to:
public void actionPerformed (ActionEvent event) { }