Java Reference
In-Depth Information
Display 18.2
A Window Listener (part 3 of 3)
70
71
public static void main(String[] args)
72
{
WindowListenerDemo demoWindow = new WindowListenerDemo();
73
74
demoWindow.setVisible( true );
Even if you have a window listener, you
normally must still invoke
setDefaultCloseOperation .
75
}
76
77
public WindowListenerDemo()
78
{
79
setSize(WIDTH, HEIGHT);
80
setTitle("Window Listener Demonstration");
81
82
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
83
addWindowListener( new CheckOnExit());
84
85
getContentPane().setBackground(Color.LIGHT_GRAY);
JLabel aLabel = new JLabel("I like to be sure you are sincere.");
86
87
add(aLabel);
88
}
89
}
R ESULTING GUI
This window is an object of
the class ConfirmWindow .
When you click this close-
window button, the second
window appears.
Are you sure you want to exit?
I like to be sure you are sincere.
 
Search WWH ::




Custom Search