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

// This class provides an example of listening to a button and being able
to close the window and terminate the progam. Has two classes at outer level
public class Applic extends CloseableFrame 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(this);
   
     pack();
     setVisible(true);
  }
 
  // Disable the enabled button and enable the disabled one
  public void actionPerformed(ActionEvent e) {
     boolean b= (be.isEnabled());
     be.setEnabled(!b);
     bw.setEnabled(b);
  }
  
}

// A closeable frame with title t
public class CloseableFrame extends JFrame
			   implements WindowListener {
	// Constructor: a Frame with good closebox
	public CloseableFrame(String t) {
	   super(t);
	   addWindowListener(this); 
	}
			   
	// Terminate program. Called when closebox pressed
	public void windowClosing(WindowEvent e)
	    { System.exit(0); }	

     // Each of the following methods deals with one
	// of the window boxes or with some action on the
	// window. They donšt do anything
			   
	public void windowClosed(WindowEvent e) {}   
	public void windowDeiconified(WindowEvent e) {}   
	public void windowIconified(WindowEvent e) {}   
	public void windowActivated(WindowEvent e) {}   
	public void windowDeactivated(WindowEvent e) {}   
	public void windowOpened(WindowEvent e) {}   
}
