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

// This class provides an example of listening to a button, with an inner
// class that provides a method to terminate the program when hitting the
// the close button.
public class Applic1 extends JFrame implements ActionListener{
  private JButton bw= new JButton("first");
  private JButton be= new JButton("second");
  
  public static void main(String pars[]) {
     Applic jF= new Applic("JFrame");
  }
  
  // Constructor: a frame with two buttons and title t  
  public Applic(String t) {
     super(t);
     // Add the two buttons to the frame
        getContentPane().add(bw, BorderLayout.WEST);
        getContentPane().add(be, BorderLayout.EAST);
  
     bw.setEnabled(false);
     be.setEnabled(true);
     
     // Register the actionlistener for the buttons
        bw.addActionListener(this);
        be.addActionListener(this);
        
     addWindowListener(new ExitOnClose()); 
   
     pack();
     setVisible(true);
  }
  
  private class ExitOnClose extends WindowAdapter {
		// Terminate program when closebox pressed
		public void windowClosing(WindowEvent e)
	    		{ System.exit(0); }	
	}

 
  // Disable the enabled button and enable the disabled one
  public void actionPerformed(ActionEvent e) {
     boolean b= (be.isEnabled());
     be.setEnabled(!b);
     bw.setEnabled(b);
  }
  
}
