VoteCounterPanel - /* / / /...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
//********************************************************* // // // Demonstrates a graphical user interface and event listeners to // tally votes for two candidates, Joe and Sam. //********************************************************* import java.awt.*; import java.awt.event.*; import javax.swing.*; public class VoteCounterPanel extends JPanel { private int votesForJoe; private JButton joe; private JLabel labelJoe; private int votesForSam; private JButton sam; private JLabel labelSam; //---------------------------------------------- // Constructor: Sets up the GUI. //---------------------------------------------- public VoteCounterPanel() { //initialize counts votesForJoe = 0; votesForSam = 0; joe = new JButton("Vote for Joe"); joe.addActionListener(new JoeButtonListener()); sam = new JButton("Vote for Sam"); sam.addActionListener(new SamButtonListener()); labelJoe = new JLabel("Votes for Joe: " + votesForJoe); labelSam = new JLabel("Votes for Sam: " + votesForSam);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

VoteCounterPanel - /* / / /...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online