`

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

    A good guideline about how to respond to editors and reviewers. Share fun!

    Neural Responding Machine for Short-Text Conversation.pdf

    Neural Responding Machine for Short-Text Conversation.pdf

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

    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连接负载机失败,提示“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 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.

    Manning.Arduino.in.Action.2013

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

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

    XML processing with Java

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

    Domain-Driven Design

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

Global site tag (gtag.js) - Google Analytics