java中关闭时处理和退出的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19433358/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between dispose and exit on close in java
提问by Ayvadia
I have a single frame created using Netbeans GUI builder when I view the frame properties one of the first options is default close operation the options listed are: DISPOSE_ON_CLOSE
, HIDE_ON_CLOSE
, DO_NOTHING_ON_CLOSE
& EXIT_ON_CLOSE
I understand the middle two but, whats the difference between DISPOSE_ON_CLOSE
and EXIT_ON_CLOSE
? I have tried testing both but to me they do the same thing to me
当我查看框架属性时,我使用 Netbeans GUI 构建器创建了一个框架,其中第一个选项是默认关闭操作,列出的选项是:DISPOSE_ON_CLOSE
, HIDE_ON_CLOSE
, DO_NOTHING_ON_CLOSE
&EXIT_ON_CLOSE
我了解中间两个但是,DISPOSE_ON_CLOSE
和之间有什么区别EXIT_ON_CLOSE
?我试过测试两者,但对我来说他们对我做同样的事情
采纳答案by Garrett Hall
EXIT_ON_CLOSE
will terminate the program.
EXIT_ON_CLOSE
将终止程序。
DISPOSE_ON_CLOSE
will call dispose()
on the frame, which will make it disappear and remove the resources it is using. You cannot bring it back, unlike hiding it.
DISPOSE_ON_CLOSE
将调用dispose()
框架,这将使其消失并删除它正在使用的资源。你不能把它带回来,不像隐藏它。
See aslo JFrame.dispose() vs System.exit()
回答by Katana24
If you have a few JFrames open and you close the one that is set to EXIT_ON_CLOSE
then all of the frames will be closed.
如果您打开了几个 JFrame 并关闭了设置为的一个,EXIT_ON_CLOSE
则所有框架都将关闭。
The opposite applies to the one with the DISPOSE_ON_CLOSE
i.e. only it will be closed
相反的情况适用于DISPOSE_ON_CLOSE
ie only 它会被关闭的那个