import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Punch_Buttons_3 extends JFrame //implements ActionListener
{
    private JLabel result;
    private JButton yes, no;
    private JLabel counts;
    private int yea, nay;

    public Punch_Buttons_3()
    {

	setTitle("Slap Me");

	JLabel lab = new JLabel("Punch a Button");
	getContentPane().add(lab, "North");
	
	result = new JLabel("");
	getContentPane().add(result, "South");

	yea =0;
	nay =0;
	counts = new JLabel("No has been clicked (" + nay + ") while yes has ben punched (" + yea + ")" );
	getContentPane().add(counts);

	yes = new JButton("Yes");
	getContentPane().add(yes, "West");
	yes.addActionListener(new Handle_Yes() );

	no = new JButton ("No");
	getContentPane().add(no, "East");
	no.addActionListener(new Handle_No() );


	//added to enable close windows to exit
	addWindowListener(new WindowHandler() );

    }


    class WindowHandler extends WindowAdapter
    {
	public void windowClosing(WindowEvent e)
	{ System.exit(0); }
    }

    class Handle_Yes implements ActionListener
    {
	public void actionPerformed( ActionEvent evt)
	{
	    yea++;
	    counts.setText("No has been clicked (" + nay + ") while yes has ben punched (" + yea + ")" );;
	    result.setText("You pressed the Yes Button.");
	}
    }


    class Handle_No implements ActionListener
    {
	public void actionPerformed( ActionEvent evt )
	{
	    nay++;
	    counts.setText("No has been clicked (" + nay + ") while yes has ben punched (" + yea + ")" );
	    result.setText("You pressed the No Button.");
	}
    }

    public static void main( String []args )
    {
	JFrame jf=new Punch_Buttons_3();
	jf.setSize(500,300);
	jf.setVisible(true);
    }
}

