// $Id: BottomPanel.java,v 1.1 2009/01/18 03:06:26 durant Exp durant $

package edu.msoe.durant;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * class representing the bottom panel.  It has some private attributes, but provides the public
 * "ButtonListener" ActionListener class so that other parts of the UI (in this case, just the
 * top panel) can notify it that it needs to do something without being concerned with its
 * inner workings (attributes, methods, etc.).
 * @author Dr. Durant [durant@msoe.edu]
 */	
class BottomPanel extends JPanel {
	// Declare attributes for information that we need to track or access across multiple method calls
	// Attributes initialized with this syntax are initialized before any constructors of this class run.
	private JLabel theLabel = new JLabel();
	private int clickCount = 0; 

	/**
	 * sets up the panel's UI elements
	 */
	public BottomPanel() {
		syncText();
		this.add(theLabel);
	}

	/**
	 * synchronizes the text displayed in the GUI with the object state (value of clickCount attribute).
	 * Note that both the constructor and ButtonListener use this method.
	 */
	private void syncText() {
		theLabel.setText("I've been clicked " + clickCount + " times.");
	}

	private static final long serialVersionUID = 1L;

	/**
	 * class for object that is notified via the Swing framework when an action
	 * has been performed that the UI must respond to
	 */
	public class ButtonListener implements ActionListener {
		@Override // this tells the Java compiler that we think we're about to implement
		// a method that someone else specified (in this case, the ActionListener
		// interface).  If the Java compiler detects that we're not really doing
		// this (perhaps we got the parameter type for actionPerformed wrong),
		// it will generate a clear error message during compilation.
		public void actionPerformed(ActionEvent arg0) {
			++clickCount;
			syncText();			
		}
	}
}
