I created a JFrame as follows:
public class XFrame extends JFrame { public XFrame() { setSize(100, 100); } @Override public void dispose() { super.dispose(); System.out.println("Dispose get called"); } public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { XFrame f = new XFrame(); f.setTitle("Hello World"); //f.setDefaultCloseOperation(DISPOSE_ON_CLOSE); f.setDefaultCloseOperation(EXIT_ON_CLOSE); f.setVisible(true); } }); } }
I expect that when I press the close button [X], the dispose method is called. However, this is a situation where DISPOSE_ON_CLOSE is set as DefaultCloseOperation (???). Java really surprises me here. How to implement a method that will be called in both cases with the DefaultCloseOperation values (DISPOSE_ON_CLOSE and EXIT_ON_CLOSE)?
EXIT_ON_CLOSE, , "" , JVM . "" , dispose, -, .
EXIT_ON_CLOSE
dispose
, Swing , Swing. , setSize() setLocation() setBounds() – 2 , ? , .
setSize()
setLocation()
setBounds()
, - , , WindowListener windowClosing().
WindowListener
windowClosing()
WindowListener windowClosing()? , , .
: - , , - dispose(), windowClosing().
dispose , . , ( javadoc), DISPOSE_ON_EXIT...System.exit, EXIT_ON_CLOSE, , , - ( ).
DISPOSE_ON_EXIT
System.exit
EXIT_ON_CLOSE - , SecurityManager
, EXIT_ON_CLOSE JFrame.EXIT_ON_CLOSE?
Source: https://habr.com/ru/post/1725522/More articles:ActiveX on Linux with Mono? - linuxKill a random process named - linuxAssociating WPF TreeView with a generic view model - wpfProblems using git merge - gitWhy does Django say that I have not set DATABASE_ENGINE yet? - pythonСтрока как ключ в HashMap - javaSelect the first element that does not have a specific class - javascriptJavaScript: How to change the hash in the address bar WITHOUT adding an entry to the history? - javascriptsynchronization of two heterogeneous databases - databaseMS Access 2007 sql functions? - functionAll Articles