1. Windowclosing is called when closing
2. WindowClosed is called in the off state, Windowclosing uses the method Dispose (), and the method can call windowclosed automatically.
3. If the windowclosing uses System.exit (0); WindowClosed is not called because the virtual machine was exited.
Look at the following code
Package Test;import Java.awt.frame;import Java.awt.event.windowadapter;import java.awt.event.windowevent;public Class Test extends Frame {public Test (String title) {Super (title), Addwindowlistener (new Windowadapter () {public void wind Owclosing (WindowEvent e) {Dispose ();} public void windowclosed (WindowEvent e) {System.out.println ("windowclosed method called");}); SetSize ($); Setlocationrelativeto (null); setvisible (true);} public static void Main (string[] args) {new test ("Test");}}
The console will print "WindowClosed method is called".
Dispose (); Change to System.exit (0); It won't print!
Windowclosing and windowclosed in java.awt