![]() ![]() ![]() |
6
Exit Frame
Features of JCExitFrame
Properties
Methods and Constructors
Examples
6.1 Features of JCExitFrame
A subclass of
JFrame
that listens for window close events and exits the application when the event is received, or hides the window so that it can be made visible later on. There is aJFrame
constant in JavaTM2 v1.3 calledEXIT_ON_CLOSE
that performs the same function.
It is useful for applications containing a single frame. If you used the utility frames available in JClass 3.x versions of jclass.contrib, it is useful to know that this replaces
DemoFrame
andContribFrame
.
6.2 Properties
A
JCExitFrame
has the same properties as aJFrame
, and one additional one:
For a full listing of the properties, please see Appendix A, Bean Properties Reference.
6.3 Methods and Constructors
Methods
JCExitFrame
subclasses fromJFrame
, making it aJFrame
with a built-in mechanism for catching window-closing events. The following methods report or control which action is taken when a window-closing event is received.Constructors
There are two constructors. The default constructor provides an untitled frame while the other accepts a parameter which is used to set the frame's title.
6.4 Examples
Use a
import java.awt.Font;JCExitFrame
as you would aJFrame
, and manage window closing events using theexitOnClose
property.
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import com.klg.jclass.util.swing.*;
public class ExitFrameExample {
static String message0 = "Many JClass examples and demos use a JCExitFrame.";
static String message1 = "\n\nKeep in mind that you can hide a JCExitFrame \nrather than disposing of it entirely.";
static String message = message0 + message1;
static JTextArea messageArea = new JTextArea(message);
public static void main(String[] args){
String title = "A Basic Frame That Responds to Window-Closing Events";
JCExitFrame frame;
frame = new JCExitFrame(title);
frame.setSize(450, 100);
frame.setVisible(true);
frame.setExitOnClose(false); // Hide the window
// instead of closing it.
messageArea.setFont(new Font("Times-Roman", Font.BOLD, 14));
frame.getContentPane().add(new JScrollPane(messageArea), "Center");
messageArea.setVisible(true);
}
}
Figure 29 : A JCExitFrame containing a JTextArea.
![]() ![]() ![]() |