zoukankan      html  css  js  c++  java
  • Swing---WindowConstants

      Java桌面开发过程中,很多人都写过类似下面的代码。 

     1 import javax.swing.JFrame;
     2 
     3 public class SimpleFrame {
     4     public static void main(String[] args) {
     5         JFrame w = new JFrame();
     6         w.setTitle("SimpleFrame");
     7         w.setSize(400, 300);
     8         w.setLocation(200, 200);
     9         
    10         w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    11         w.setVisible(true);
    12     }
    13 }

      代码虽然简单,但是其中还是包含点我不知道的知识点。下面结合自己学习的内容介绍一下WindowConstants接口。

     1 package javax.swing;
     2 
     3 public interface WindowConstants
     4 {   // The do-nothing default window close operation.
     5     public static final int DO_NOTHING_ON_CLOSE = 0;  6     // The hide-window default window close operation.
     7     public static final int HIDE_ON_CLOSE = 1;  8     // The dispose-window default window close operation.
     9     public static final int DISPOSE_ON_CLOSE = 2; 
    10     // The exit application default window close operation.
    11     public static final int EXIT_ON_CLOSE = 3; 
    12 
    13 }
    常量名 代表值 含义
    DO_NOTHING_ON_CLOSE 0 关闭窗体时,不执行任何操作  
    HIDE_ON_CLOSE 1 关闭窗体时,窗体自动隐藏
    DISPOSE_ON_CLOSE 2 关闭窗体时,自动隐藏并释放窗体
    EXIT_ON_CLOSE 3 关闭窗体时,退出应用程序(Application非Applet)

       原来这些常量并非是JFrame所特有的,而是在一个特定的接口中定义的。当然,在WindowConstants接口中也有相关说明: The setDefaultCloseOperation and getDefaultCloseOperation methods provided by JFrame, JInternalFrame, and JDialog. 也就是说,JFrame、JInternalFrame和JDialog也实现了WindowConstants接口。

      JFrame中重新定义了 public static final int EXIT_ON_CLOSE = 3; ,因此上面代码中的 JFrame.EXIT_ON_CLOSE 无论无何是合理的。

      ,

  • 相关阅读:
    sublime如何自动保存
    什么是DQL、DML、DDL、DCL
    Linux Shall命令入门
    省市区地址三级联动jQuery插件Distpicker使用
    ThinkPHP3.2设置404跳转页面
    File.separator
    HiddenHttpMethodFilter
    SpringMVC环境搭建
    JVM介绍(一)
    some characters cannot be mapped using iso-8859-1 character encoding
  • 原文地址:https://www.cnblogs.com/forget406/p/5279969.html
Copyright © 2011-2022 走看看