zoukankan      html  css  js  c++  java
  • JFrame关闭事件处理

    1、JFrame实现WindowListener

    2、将当前窗口加入监听

    this.addWindowListener(this);
      //按关闭按钮,啥事也不做
    this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

    3、实现windowClosing方法

    /**
      * 关闭主窗口处理
      */
     @Override
     public void windowClosing(WindowEvent e) {
           int option = JOptionPane.showConfirmDialog(this, "确定退出系统?", "提示",
           JOptionPane.YES_NO_OPTION);
           if (option == JOptionPane.YES_OPTION)
           {
                   if (e.getWindow() == this) {
                          this.dispose();
                          System.exit(0);
           } else {
                  return;
           }
        }
       else if(option == JOptionPane.NO_OPTION){
              if (e.getWindow() == this) {
                       return;
              }
         }
     }

    OK!

  • 相关阅读:
    git
    搁置:vue-element-admin
    JS
    开发心得
    CSS
    VSCode(主进程)
    Vue
    axios
    滚动条出现的原理
    element-ui 1.4.13
  • 原文地址:https://www.cnblogs.com/zhishan/p/2627108.html
Copyright © 2011-2022 走看看