•     JDK :OpenJDK-11
  •      OS :CentOS 7.6.1810
  •      IDE :Eclipse 2019‑03
  • typesetting :Markdown

code

package per.jizuiku.gui;

import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; /**
* @author 给最苦
* @date 2019/06/30
* @blog www.cnblogs.com/jizuiku
*/
public class Demo { /**
* @param args
*/
public static void main(String[] args) {
// 创建窗体对象并给出标题
String title = "点击红叉关闭退出程序";
Frame f = new Frame(title); // 这里是重点,WindowAdapter适配器类
/*
* 事件源 f
* 事件 WindowsListener
* 事件处理 new WindowAdapter(){}
* 事件监听 f.addWindowListener(new WindowAdapter(){})
*/
f.addWindowListener(new WindowAdapter() {
// 只要重写 点击红叉 的事件处理函数就好
@Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
System.out.println("程序运行结束");
System.exit(0);
}
}); // 可见
f.setVisible(true); } }

result

console

程序运行结束

sourceCode

/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/ package java.awt.event; /**
* An abstract adapter class for receiving window events.
* The methods in this class are empty. This class exists as
* convenience for creating listener objects.
* <P>
* Extend this class to create a {@code WindowEvent} listener
* and override the methods for the events of interest. (If you implement the
* {@code WindowListener} interface, you have to define all of
* the methods in it. This abstract class defines null methods for them
* all, so you can only have to define methods for events you care about.)
* <P>
* Create a listener object using the extended class and then register it with
* a Window using the window's {@code addWindowListener}
* method. When the window's status changes by virtue of being opened,
* closed, activated or deactivated, iconified or deiconified,
* the relevant method in the listener
* object is invoked, and the {@code WindowEvent} is passed to it.
*
* @see WindowEvent
* @see WindowListener
* @see <a href="http://docs.oracle.com/javase/tutorial/uiswing/events/windowlistener.html">Tutorial: Writing a Window Listener</a>
*
* @author Carl Quinn
* @author Amy Fowler
* @author David Mendenhall
* @since 1.1
*/
public abstract class WindowAdapter
implements WindowListener, WindowStateListener, WindowFocusListener
{
/**
* Invoked when a window has been opened.
*/
public void windowOpened(WindowEvent e) {} /**
* Invoked when a window is in the process of being closed.
* The close operation can be overridden at this point.
*/
public void windowClosing(WindowEvent e) {} /**
* Invoked when a window has been closed.
*/
public void windowClosed(WindowEvent e) {} /**
* Invoked when a window is iconified.
*/
public void windowIconified(WindowEvent e) {} /**
* Invoked when a window is de-iconified.
*/
public void windowDeiconified(WindowEvent e) {} /**
* Invoked when a window is activated.
*/
public void windowActivated(WindowEvent e) {} /**
* Invoked when a window is de-activated.
*/
public void windowDeactivated(WindowEvent e) {} /**
* Invoked when a window state is changed.
* @since 1.4
*/
public void windowStateChanged(WindowEvent e) {} /**
* Invoked when the Window is set to be the focused Window, which means
* that the Window, or one of its subcomponents, will receive keyboard
* events.
*
* @since 1.4
*/
public void windowGainedFocus(WindowEvent e) {} /**
* Invoked when the Window is no longer the focused Window, which means
* that keyboard events will no longer be delivered to the Window or any of
* its subcomponents.
*
* @since 1.4
*/
public void windowLostFocus(WindowEvent e) {}
}

resource

  • [ JDK ] openjdk.java.net
  • [ doc - 参考 ] docs.oracle.com/en/java/javase/11
  • [ 规范 - 推荐 ] yq.aliyun.com/articles/69327
  • [ 规范 - 推荐 ] google.github.io/styleguide
  • [ 源码 ] hg.openjdk.java.net
  • [ OS ] www.centos.org
  • [ IDE ] www.eclipse.org/downloads/packages
  • [ 平台 ] www.cnblogs.com


感谢帮助过 给最苦 的人们。

Java、Groovy和Scala等基于JVM的语言,优秀,值得学习。

规范的命名和代码格式等,有助于沟通和理解。

JVM的配置、监控与优化,比较实用,值得学习。

Java基础 awt Frame 点击叉后,在控制台输出提示信息并关闭程序的更多相关文章

  1. Java基础 awt Button 点击按钮后在控制台输出文字

        JDK :OpenJDK-11      OS :CentOS 7.6.1810      IDE :Eclipse 2019‑03 typesetting :Markdown   code ...

  2. Java基础 awt Frame 设置窗体的背景颜色

        JDK :OpenJDK-11      OS :CentOS 7.6.1810      IDE :Eclipse 2019‑03 typesetting :Markdown   code ...

  3. Java基础 awt Frame 窗体的大小不可调

        JDK :OpenJDK-11      OS :CentOS 7.6.1810      IDE :Eclipse 2019‑03 typesetting :Markdown   code ...

  4. Java基础 awt Frame 设置窗体的大小 位置 可见性

        JDK :OpenJDK-11      OS :CentOS 7.6.1810      IDE :Eclipse 2019‑03 typesetting :Markdown   code ...

  5. Java基础 awt Frame 窗体在屏幕的中间显示

        JDK :OpenJDK-11      OS :CentOS 7.6.1810      IDE :Eclipse 2019‑03 typesetting :Markdown   code ...

  6. Java基础---AWT

    流式布局FlowLayout package net.zyz; import java.awt.Button; import java.awt.FlowLayout; import java.awt. ...

  7. Java基础 awt Button 鼠标放在按钮上背景颜色改变,鼠标离开背景颜色恢复

        JDK :OpenJDK-11      OS :CentOS 7.6.1810      IDE :Eclipse 2019‑03 typesetting :Markdown   code ...

  8. Java基础 awt Graphics2D 生成矩形图片并向内写入字符串

        JDK :OpenJDK-11      OS :CentOS 7.6.1810      IDE :Eclipse 2019‑03 typesetting :Markdown   code ...

  9. Java基础 awt Graphics2D 生成矩形图片并向其中画一条直线

        JDK :OpenJDK-11      OS :CentOS 7.6.1810      IDE :Eclipse 2019‑03 typesetting :Markdown   code ...

随机推荐

  1. C# 获取指定类型的文件

    C# 获取指定类型的文件 public static List<FileInfo> getFile(string path, string extName) { List<FileI ...

  2. 控制跳转的tree视图显示的列表项数量

    在act_window中,定义limit字段,可以指定打开的tree视图的记录数量.   limit:列表视图中每个页面的记录数.

  3. Diagnostic Viewer 显示空白

    MATLAB R2014a仿真出现错误后,查找错误时,Diagnostic Viewer 显示空白.网上查的一种解决方法.我的电脑是Windows7. 1.点击 所有程序>附件>记事本(以 ...

  4. Win10系统如何关闭自动更新?

    现在很多电脑的系统都升级到了win10了,win10已经渐渐普及到每个人的电脑中,但是,win10系统有一个功能特别讨人厌,我自认为挺讨厌这个功能的,它就是“自动更新”功能,你可能会说,自动更新不是挺 ...

  5. spring cloud 学习资料

    spring cloud 学习资料 网址 拜托!面试请不要再问我Spring Cloud底层原理 https://mp.weixin.qq.com/s/ZH-3JK90mhnJPfdsYH2yDA

  6. BJOI2018 day2

    双人猜数游戏 Alice 和 Bob 是一对非常聪明的人,他们可以算出各种各样游戏的最优策略.现在有个综艺节目<最强大佬>请他们来玩一个游戏.主持人写了三个正整数 \(s\) .\(m\) ...

  7. 【Java】Springboot集成Druid

    Springboot集成Druid方案:一个是在POM中直接配置druid-spring-boot-starter,不用写任何代码:一个是配置druid,写几行代码,可以加入:在方案一基础上加入sta ...

  8. JavaScript基础08——DOM

    DOM的概念 DOM是document Object Model的缩写,简称文档对象模型.他给文档提供了一种结构化的表示方式,可以改变文档的内容和呈现方式 所谓的DOM是以家族的形式描述HTML.父子 ...

  9. Xamarin.Android开发中遇到的问题

    开发 1.Resource.Id未包含xxx的定义 打开了一个OK的Id,是位于\obj\Debug\90\designtime\Resource.designer.cs ,打开文件搜索xxx,果然没 ...

  10. ent facebook 开源的golang orm 框架

    ent 是facebook 开源的golang orm 框架,简单强大,具有提下特性 schema 即代码 方便的图遍历 静态类型以及显示api 多种存储引擎支持(当前是mysql,sqlite,以及 ...