zoukankan      html  css  js  c++  java
  • JAVA 关闭窗口的设置 DISPOSE_ON_CLOSE和EXIT_ON_CLOSE 的区别

    static int DISPOSE_ON_CLOSE
    移除窗口的默认窗口关闭操作。
    static int DO_NOTHING_ON_CLOSE
    无操作默认窗口关闭操作。
    static int EXIT_ON_CLOSE
    退出应用程序默认窗口关闭操作。
    static int HIDE_ON_CLOSE
    隐藏窗口的默认窗口关闭操作

    setDefaultCloseOperation()是用来设定窗口被关闭时候(比如点击了右上角的"x")的行为的。 

    DISPOSE_ON_CLOSE在窗口被关闭的时候会dispose这个窗口。 

    EXIT_ON_CLOSE在窗口被关闭的时候会退出JVM。 


    如果你的程序没有其他线程在运行的话,当所有的窗口都被dispose了之后,JVM也会退出。


    package xiya;
    import javax.swing.*;
    import static javax.swing.JFrame.*;
    
    public class Example10_1 {
    	public static void main(String[] args) {
    		JFrame windows1 = new JFrame("窗口一");
    		JFrame windows2 = new JFrame("窗口二");
    		
    		windows1.setBounds(200,100,360,260);
    		windows2.setBounds(560,100,360,260);
    		
    		windows1.setVisible(true);
    		windows1.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    		windows2.setVisible(true);
    		windows2.setDefaultCloseOperation(EXIT_ON_CLOSE);
    		
    	}
    
    }
    


  • 相关阅读:
    使用Python往手机发送短信(基于twilio模块)
    春&风
    故乡
    非常完美
    风 记忆
    风誓
    MATLAB的循环结构
    你要的快乐
    夕颜
    MATLAB的基本元素
  • 原文地址:https://www.cnblogs.com/lgh1992314/p/5835286.html
Copyright © 2011-2022 走看看