Chris Johnson, Index
Event Handling - Listeners

/*
* Simple warning program
*
* Author: Chris Johnson (johnson@dcs.gla.ac.uk)
* Last revision date: 11/10/98
*
* Produces a simple warning on the screen.   Illustrates the
* use of a frame and of a simple event handler in AWT 1.1
 */
 
import java.awt.*;
import java.awt.event.*;
 
public class CloseableSimpleWarning extends Frame implements
WindowListener
{
 
static private final int frame_height = 150;
static private final int frame_width = 250;
 
        public CloseableSimpleWarning()
        {
                setTitle("Warning");
                setSize(frame_width, frame_height);
                addWindowListener(this); // Listens for this frame
        }
 
        public void windowClosing (WindowEvent e)
        {
                System.exit(0);
        }
 
        public void windowClosed (WindowEvent e)
        {
                System.exit(0);
        }
 
        public void windowIconified (WindowEvent e)
        {
                System.exit(0);
        }
 
        public void windowDeiconified (WindowEvent e)
        {
                System.exit(0);
        }
 
                public void windowOpened (WindowEvent e)
        {
                System.exit(0);
        }
 
  public void windowActivated (WindowEvent e)
        {
                System.exit(0);
        }
 
        public void windowDeactivated (WindowEvent e)
        {
                System.exit(0);
        }
 
        public static void main(String [] args)
        {
                CloseableSimpleWarning f = new CloseableSimpleWarning();
                f.show();
        }
}

forward