System.exit(0) vs JFrame.EXIT_ON_CLOSE

[亡魂溺海] 提交于 2019-12-05 01:42:46

If you look at the JFrame code, it does:

 protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);

        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
            switch(defaultCloseOperation) {
              ...
          case EXIT_ON_CLOSE:
                  // This needs to match the checkExit call in
                  // setDefaultCloseOperation
        System.exit(0);
        break;
            }
        }
    }

So, it's exactly the same thing. I would just set EXIT_ON_CLOSE if that's what you want it to do.

Well, considering System.exit(0) is in the JFrame coding, either would work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!