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

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

class ButtonPanel3 extends JPanel
{
	JButton button1, button2;
	JLabel label;
	int numberOfPresses = 0;
	
	//  Constructor
	//  Sets up a panel with 2 buttons and a Label.  The label tells how many
	//  times the buttons have been pressed (with one button counting as two presses)
	public ButtonPanel3()
	{
		button1 = new JButton("Plus 1!");
		add(button1);
		button1.addActionListener(new ButtonListener(1));
		button2 = new JButton("Plus 2!");
		add(button2);
		button2.addActionListener(new ButtonListener(2));

		label = new JLabel("Number of Button Preses = " + numberOfPresses);
		add(label);
		setPreferredSize(new Dimension(250, 100));
	}
	
	private class ButtonListener  implements ActionListener
	{
		int delta;
		
		// Constructor for listener attached to buttons. 
		// INPUTS:  pushDelta:  The amount we increase numberOfPresses value
		//                      when a button is pressed
		public ButtonListener(int pushDelta)
		{
			delta = pushDelta;
		}
		
		// method actionPerformed
		// Called when a button is pressed, updates the label which tells how many times
		// a button has been pressed
		public void actionPerformed(ActionEvent event) 
		{
			numberOfPresses = numberOfPresses + delta;
			label.setText("Number of Button Presses = " + numberOfPresses);
		}
		
		
	}
}