PushCounterPanel

PushCounterPanel - label = new JLabel ("Pushes: "...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//******************************************************************** // PushCounterPanel.java Authors: Lewis/Loftus // // Demonstrates a graphical user interface and an event listener. //******************************************************************** import java.awt.*; import java.awt.event.*; import javax.swing.*; public class PushCounterPanel extends JPanel { private int count; private JButton push; private JLabel label; //----------------------------------------------------------------- // Constructor: Sets up the GUI. //----------------------------------------------------------------- public PushCounterPanel () { count = 0; push = new JButton ("Push Me!"); push.addActionListener (new ButtonListener());
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: label = new JLabel ("Pushes: " + count); add (push); add (label); setPreferredSize (new Dimension(300, 40)); setBackground (Color.cyan); } //***************************************************************** // Represents a listener for button push (action) events. //***************************************************************** private class ButtonListener implements ActionListener { //--------------------------------------------------------------// Updates the counter and label when the button is pushed. //--------------------------------------------------------------public void actionPerformed (ActionEvent event) { count++; label.setText("Pushes: " + count); } } }...
View Full Document

This document was uploaded on 02/21/2011.

Ask a homework question - tutors are online