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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 17:07:19  来源:igfitidea点击:

Difference between dispose and exit on close in java

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_CLOSEI understand the middle two but, whats the difference between DISPOSE_ON_CLOSEand 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_CLOSEwill terminate the program.

EXIT_ON_CLOSE将终止程序。

DISPOSE_ON_CLOSEwill 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()

参见JFrame.dispose() 与 System.exit()

回答by Katana24

If you have a few JFrames open and you close the one that is set to EXIT_ON_CLOSEthen all of the frames will be closed.

如果您打开了几个 JFrame 并关闭了设置为的一个,EXIT_ON_CLOSE则所有框架都将关闭。

The opposite applies to the one with the DISPOSE_ON_CLOSEi.e. only it will be closed

相反的情况适用于DISPOSE_ON_CLOSEie only 它会被关闭的那个