By default, when the user closes a frame onscreen, the frame is hidden. Although invisible, the frame still exists and the program can make it visible again. If you want different behavior, then you need to either register a window listener that handles window-closing events, or you need to specify default close behavior using the setDefaultCloseOperation method. You can even do both.
The argument to setDefaultCloseOperation must be one of the following values, the first three of which are defined in the WindowConstants interface (implemented by JFrame, JInternalPane, and JDialog):
DO_NOTHING_ON_CLOSE
Do not do anything when the user requests that the window close. Instead, the program should probably use a window listener that performs some other action in its windowClosing method.
HIDE_ON_CLOSE (the default for JDialog and JFrame)
Hide the window when the user closes it. This removes the window from the screen but leaves it displayable.
DISPOSE_ON_CLOSE (the default for JInternalFrame)
Hide and dispose of the window when the user closes it. This removes the window from the screen and frees up any resources used by it.
EXIT_ON_CLOSE (defined in the JFrame class)
Exit the application, using System.exit(0). This is recommended for applications only. If used within an applet, a SecurityException may be thrown.
--------------------------------------------------------------------------------
Note: DISPOSE_ON_CLOSE can have results similar to EXIT_ON_CLOSE if only one window is onscreen. More precisely, when the last displayable window within the Java virtual machine (VM) is disposed of, the VM may terminate. See AWT Threading Issues for details.
--------------------------------------------------------------------------------
The default close operation is executed after any window listeners handle the window-closing event. So, for example, assume that you specify that the default close operation is to dispose of a frame. You also implement a window listener that tests whether the frame is the last one visible and, if so, saves some data and exits the application. Under these conditions, when the user closes a frame, the window listener will be called first. If it does not exit the application, then the default close operation — disposing of the frame — will then be performed.
For more information about handling window-closing events, see How to Write Window Listeners. Besides handling window-closing events, window listeners can also react to other window state changes, such as iconification and activation.
The argument to setDefaultCloseOperation must be one of the following values, the first three of which are defined in the WindowConstants interface (implemented by JFrame, JInternalPane, and JDialog):
DO_NOTHING_ON_CLOSE
Do not do anything when the user requests that the window close. Instead, the program should probably use a window listener that performs some other action in its windowClosing method.
HIDE_ON_CLOSE (the default for JDialog and JFrame)
Hide the window when the user closes it. This removes the window from the screen but leaves it displayable.
DISPOSE_ON_CLOSE (the default for JInternalFrame)
Hide and dispose of the window when the user closes it. This removes the window from the screen and frees up any resources used by it.
EXIT_ON_CLOSE (defined in the JFrame class)
Exit the application, using System.exit(0). This is recommended for applications only. If used within an applet, a SecurityException may be thrown.
--------------------------------------------------------------------------------
Note: DISPOSE_ON_CLOSE can have results similar to EXIT_ON_CLOSE if only one window is onscreen. More precisely, when the last displayable window within the Java virtual machine (VM) is disposed of, the VM may terminate. See AWT Threading Issues for details.
--------------------------------------------------------------------------------
The default close operation is executed after any window listeners handle the window-closing event. So, for example, assume that you specify that the default close operation is to dispose of a frame. You also implement a window listener that tests whether the frame is the last one visible and, if so, saves some data and exits the application. Under these conditions, when the user closes a frame, the window listener will be called first. If it does not exit the application, then the default close operation — disposing of the frame — will then be performed.
For more information about handling window-closing events, see How to Write Window Listeners. Besides handling window-closing events, window listeners can also react to other window state changes, such as iconification and activation.
发表评论
-
java.lang.UnsatisfiedLinkError: no j3dcore-ogl-chk in java.library.path
2011-08-19 17:01 2448Exception in thread "main& ... -
打jar包
2011-05-26 18:35 997打成jar包: 1、没有其他类库jar文件和插件 ... -
Java实现通用线程池
2011-05-05 23:11 1021线程池通俗的描述就是预先创建若干空闲线程,等到需要用多线程去处 ... -
Java tutorial
2011-05-05 21:49 971http://download.oracle.com/java ... -
java.awt.component.repaint()
2011-05-05 18:57 1004repaint public void repaint()R ... -
validate
2011-05-05 17:21 703validate public void validate( ... -
Class.forName和New的比较
2011-04-26 14:46 667在初始化一个类,生成一个实例的时候,newInstance() ... -
Map、Collection、List接口的总结
2011-04-26 02:52 789Map接口: | + -- ... -
复杂的GridBagLayout
2011-02-07 16:06 1002今天终于耐着性子弄懂了GridBagLayout是怎么使用的。 ... -
swing中的布局管理器
2011-02-07 15:42 14124.CardLayout CardL ... -
swing中的最上层组件
2011-02-07 15:05 2709swing中几乎所有组件都是从JComponent衍生而来,也 ... -
Java swing 组件分层介绍:JRootPane,GlassPane,LayeredPane
2011-02-06 17:01 2996什么是Swing,什么又是ligh ... -
JTextArea操作
2011-01-11 18:03 1196JTextArea操作: (1)在JTextArea插入 ... -
double到int转换
2010-12-16 23:28 812double到int转换,有“截断”误差的。 可以通过+0.5 ... -
各种排序算法java实现
2010-11-25 15:20 545package org.rut.util.algorith ... -
Java中使用BigDecimal进行浮点数高精度计算
2010-11-25 15:18 758转自:http://chongtianpig.netbei.c ... -
利用java内存映射文件机制实现CRC循环冗余校验
2010-11-19 13:52 1051import java.nio.MappedByteBuf ... -
java中进行二进制,八进制,十六进制,十进制间进行相互转换
2010-11-19 13:48 619十进制转成十六进制: Integer.toHexString ... -
JScrollPane 例解
2010-11-19 01:49 1505类层次结构图: java.lang.Object -- ... -
JTextField JTextArea 区分
2010-11-19 01:14 1474一、单行文本输入框(JTextField) 在许多情况下 ...
相关推荐
A good guideline about how to respond to editors and reviewers. Share fun!
Neural Responding Machine for Short-Text Conversation.pdf
- JavaScript Events And Responding To The User - JavaScript Profiling With The Chrome Developer Tools - Writing Fast, Memory-Efficient JavaScript - Designing Better JavaScript APIs
MTK 内部资料介绍ANR 相关 Outline ▪ What is ANR; ▪ ANR key info; ▪ Analyze ANR; ▪ Example; ▪ Need MTK help; ▪ Monkey ANR
* 1.3.2: Fix windows not responding and focus-follows-mouse choosing the wrong window, add an option to open windows as master * 1.3.3: Fix movement losing windows, add workaround for steam update ...
Oracle Incident Response and Forensics Preparing for and Responding to Data Breaches 英文无水印原版pdf pdf所有页面使用FoxitReader、PDF-XChangeViewer、SumatraPDF和Firefox测试都可以打开 本资源转载自...
Oracle Incident Response and Forensics Preparing for and Responding to Data Breaches 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
if the test was run a couple of times (without closing BurnInTest). Release 5.3 build 1021 WIN32 release 5 June 2008 - 32-bit BurnInTest PRO 5.3.1020 would not start on Windows 2000. This has been ...
仅发送主机名的示例:-“ https://duckduckgo.com/?q=privacy”->“ duckduckgo.com”-“ https://www.openrightsgroup.org/blog/2015/responding-to -无需隐藏-无需担心“->” www.openrightsgroup.org“ --- Icons...
在我遇到问题 info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Could not find a connected Android device.)",...
Loadrunner连接负载机失败,提示“Failed to connect to load generator.check the output window for more details”
The molecular genetics of chemotaxis: sensing and responding to chemoattractant gradients The molecular genetics of chemotaxis: sensing and responding to chemoattractant gradients Richard A. Firtel*...
This is the global socket data structure used for responding to the Out-of-the-blue (OOTB) packets. A control sock will be created for this socket at the initialization time.
Sensing and responding to events Robots, flying vehicles, Twitter machines, LCD displays, and more! Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning ...
android开发时常会碰到adb not responding,导致无法调试运行应用程序,通过DDMS的Reset adb后依旧无法解决,那么可以尝试使用此bat文件: 1、下载后点击运行,显示端口使用列表 2、找到状态为LISTENING的一行,复制...
Sensing and responding to events Robots, flying vehicles, Twitter machines, LCD displays, and more! Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning ...
responding class centres in the Euclidean space to achieve intra-class compactness. SphereFace assumes that the lin- ear transformation matrix in the last fully connected layer can be used as a ...
• Responding to individual XML parsing events with the Simple API for XML Parsing (SAX) 2.0 • Printing the outline of an XML document using SAX • Counting book orders using SAX • Transforming XML ...
Maintaining model integrity in a large system * Dealing with coexisting models on the same project * Organizing systems with large-scale structures * Recognizing and responding to modeling ...