1. 程式人生 > >常用的四種窗體關閉方式

常用的四種窗體關閉方式



import java.awt.*;
import javax.swing.*;

public class Fu extends JFrame{ 
 public Fu(String t) {
        super(t);
  Container b=getContentPane();
  b.add(new JLabel("partial"));
  setVisible(true);
  setSize(300, 190);
  //setDefaultCloseOperation()方法是把int型別常量封裝在javax.swing.WindowConstants接口裡。
  setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
  setDefaultCloseOperation(0);
  //關閉Console的紅燈,窗體才會關閉。
  setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
  setDefaultCloseOperation(1);
  //Console紅燈一直亮著。
  setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  //2       紅燈一會就滅了。
  setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  //3        立即滅掉
 }
 public static void main(String[] args) {
  new Fu("sticky");
 }
}