import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ButtonTest extends JFrame 
{
public ButtonTest()
   {
   setSize( 275, 100 );
   setDefaultCloseOperation(EXIT_ON_CLOSE);

   Container c = getContentPane();
   c.setLayout( new FlowLayout( ) ); 

   JButton exitButton = new JButton( "Exit" );
   c.add( exitButton );

   eventClass handler = new eventClass( );
   exitButton.addActionListener( handler );

   setVisible(true);
   }
	 
public static void main (String [] args)
   {
   ButtonTest app = new ButtonTest();
   }
   
private class eventClass implements ActionListener 
   {
   public void actionPerformed ( ActionEvent e ) 
      {
      // use e.getActionCommand( ); to print button label
      System.out.println(e.getActionCommand( ));
      if (e.getActionCommand().equals("Exit"))
         {
		 System.exit(0); 
		 } 
		 
      } // end actionPerformed method
   } // end private class

} // end class

