Java Reference
In-Depth Information
public ActiveFrame()
{ addWindowListener
(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0);}
}
);
setSize(300, 250);
setTitle(getClass().getName());
}
}
In addition to creating a closeable window, the ActiveFrame class sets
the window size to 300 by 250 pixels and displays the name of the driving
class as the program title. Your code can modify these default values. The
following program, named Closeable.java, creates a program window us-
ing the ActiveFrame class.
//**********************************************************
//**********************************************************
// Project: Java for Engineers
// Program: Closeable.java
// Reference: Chapter 26
// Topics:
// 1. Extending the java Frame class with ActiveFrame.
// ActiveFrame provides additional processing logic
// for closing the program window without having to
// re-boot.
// 2. Calling methods in the superclasses.
// 3. Displaying the frame using the show() method of
// the Window class.
//**********************************************************
// Requires:
// 1. ActiveFrame class in the current directory
//**********************************************************
//**********************************************************
import java.awt.*;
import ActiveFrame;
//*********************************************
//*********************************************
// driving class
//*********************************************
//*********************************************
public class Closeable extends ActiveFrame
{
// By extending ActiveFrame we make accessible all its
// methods and those of its superclasses (Object, Component,
// Container, Window, and Frame).
//****************************
// main
//****************************
Search WWH ::




Custom Search