`

Responding to Window-Closing Events

    博客分类:
  • java
UP 
阅读更多
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.
分享到:
评论

相关推荐

    Top 10 Tips for Responding to Reviewer

    在学术出版的过程中,回应审稿人的评论是一项重要而复杂的任务,这对于作者来说既是挑战也是机会。本文将详细探讨如何高效地响应审稿人评论,确保论文顺利通过审稿并最终发表。文章主要从十个方面提供应对策略,帮助...

    Understanding Advanced JavaScript

    - JavaScript Events And Responding To The User - JavaScript Profiling With The Chrome Developer Tools - Writing Fast, Memory-Efficient JavaScript - Designing Better JavaScript APIs

    Application-Not-Responding(ANR)-Analyze.pdf

    MTK 内部资料介绍ANR 相关 Outline ▪ What is ANR; ▪ ANR key info; ▪ Analyze ANR; ▪ Example; ▪ Need MTK help; ▪ Monkey ANR

    Kwin Scripts

    * 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 ...

    Neural Responding Machine for Short-Text Conversation.pdf

    这篇论文探讨了人工智能领域中自然语言处理的新方法——神经响应机(Neural Responding Machine, NRM),它是一种基于神经网络的响应生成器,专为短文本对话设计。NRM采用了一般编码-解码框架,将响应生成过程形式...

    Oracle Incident Response and Forensics Preparing for and Responding to 无水印原版pdf

    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 epub

    Oracle Incident Response and Forensics Preparing for and Responding to Data Breaches 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书

    BURNINTEST--硬件检测工具

    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 ...

    SSL Server Test-crx插件

    仅发送主机名的示例:-“ https://duckduckgo.com/?q=privacy”->“ duckduckgo.com”-“ https://www.openrightsgroup.org/blog/2015/responding-to -无需隐藏-无需担心“->” www.openrightsgroup.org“ --- Icons...

    haxm-windows_v7_0_0

    在我遇到问题 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连接负载机失败

    在使用Loadrunner进行性能测试时,用户可能会遇到“Loadrunner连接负载机失败”的情况,具体表现为:尝试连接负载机时出现错误提示“Failed to connect to load generator. Check the output window for more ...

    The molecular genetics of chemotaxis: sensing and responding to chemoattractant gradients

    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*...

    oom.rar_Out Of The Blue

    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.

    adb not responding

    android开发时常会碰到adb not responding,导致无法调试运行应用程序,通过DDMS的Reset adb后依旧无法解决,那么可以尝试使用此bat文件: 1、下载后点击运行,显示端口使用列表 2、找到状态为LISTENING的一行,复制...

    Arduino in Action

    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 ...

    人脸识别2019

    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 ...

    Building Serverless Architectures-Packt Publishing(2017).pdf

    Lambda designed to run code pieces responding to external or internal cloud events, without needing to set up any infrastructure upfront, and it brought a real, managed, and pay-per-go infrastructure...

    STM32F4 Discovery usb蓝牙模块驱动 - UUBT

    Besides that I can see my board responding to remote l2ping, hcitool name, hcitool scan and possibly more. To observe app main function, connect rfcomm port (sudo rfcomm |bind> 0 <bdaddr> 1), start ...

    sbsel110.pdf

    Battery Selector must be capable of responding to these events without compromising the integrity of the system’s power supply. Additionally, the selector should notify the system’s power ...

Global site tag (gtag.js) - Google Analytics