blob: 5a38e94641658e1d3bf991ea17d1610848f99e1e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
/* Listing2901.java */
import java.awt.*;
import java.awt.event.*;
class CloseableFrame
extends Frame
{
public CloseableFrame()
{
this("");
}
public CloseableFrame(String title)
{
super(title);
addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent event)
{
setVisible(false);
dispose();
}
}
);
}
}
public class Listing2901
{
public static void main(String[] args)
{
CloseableFrame wnd = new CloseableFrame("CloseableFrame");
wnd.setBackground(Color.lightGray);
wnd.setSize(300,200);
wnd.setLocation(200,100);
wnd.setVisible(true);
wnd.addWindowListener(
new WindowAdapter() {
public void windowClosed(WindowEvent event)
{
System.out.println("terminating program...");
System.exit(0);
}
}
);
}
}
|