知识大全 java关闭窗体的六种方法

Posted

篇首语:不飞则已,一飞冲天;不鸣则已,一鸣惊人。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 java关闭窗体的六种方法相关的知识,希望对你有一定的参考价值。

  前段时间集中精力写了两篇论文 很久没写博文了 现在继续了

   使用JFrame的enableEvents和processWindowEvent

  //Frame java

  import java awt *;

  import java awt event *;

  import javax swing *;

  public class Frame extends JFrame

  public Frame ()

  enableEvents(AWTEvent WINDOW_EVENT_MASK);

  this setSize(new Dimension( ));

  this setTitle( Frame );

  

  protected void processWindowEvent(WindowEvent e)

  super processWindowEvent(e);

  if (e getID() == WindowEvent WINDOW_CLOSING)

  System exit( );

  

  

  

   直接实现WindowListener接口

  //Frame java

  import java awt *;

  import java awt event *;

  public class Frame extends Frame implements WindowListener

  public Frame ()

  this setSize(new Dimension( ));

  this setTitle( Frame );

  this addWindowListener(this);

  

  public void windowClosing(WindowEvent windowEvent)

  System exit( );

  

  public void windowOpened(WindowEvent windowEvent)  

  public void windowClosed(WindowEvent windowEvent)  

  public void windowIconified(WindowEvent windowEvent)  

  public void windowDeiconified(WindowEvent windowEvent)  

  public void windowActivated(WindowEvent windowEvent)  

  public void windowDeactivated(WindowEvent windowEvent)  

  

   直接继承窗体适配器WindowAdapter

  //Frame java

  import java awt *;

  import java awt event *;

  public class Frame extends  WindowAdapter

  public Frame ()

  Frame f=new Frame();

  f setSize(new Dimension( ));

  f setTitle( Frame );

  f addWindowListener(this);

  f setVisible(true);

  

  public static void main(String[] s)

  new Frame ();

  

  public void windowClosing(WindowEvent windowEvent)

  System exit( );

  

  

   间接继承窗体适配器WindowAdapter

  //Frame java

  import java awt *;

  import java awt event *;

  public class Frame extends  Frame

  public Frame ()

  this setSize(new Dimension( ));

  this setTitle( Frame );

  this addWindowListener(new winAdapter());

  this setVisible(true);

  

  public static void main(String[] s)

  new Frame ();

  

  

  class winAdapter extends WindowAdapter

  public void windowClosing(WindowEvent windowEvent)

  System exit( );

  

  

   间接实现WindowListener接口

  //Frame java

  import java awt *;

  import java awt event *;

  public class Frame extends  Frame

  public Frame ()

  this setSize(new Dimension( ));

  this setTitle( Frame );

  this addWindowListener(new winEventHandle());

  this setVisible(true);

  

  public static void main(String[] s)

  new Frame ();

  

  

  class winEventHandle implements WindowListener

  public void windowClosing(WindowEvent windowEvent)

  System exit( );

  

  public void windowOpened(WindowEvent windowEvent)  

  public void windowClosed(WindowEvent windowEvent)  

  public void windowIconified(WindowEvent windowEvent)  

  public void windowDeiconified(WindowEvent windowEvent)  

  public void windowActivated(WindowEvent windowEvent)  

  public void windowDeactivated(WindowEvent windowEvent)  

  

   使用Inner Class

  //Frame java

  import java awt *;

  import java awt event *;

  public class Frame

  public Frame ()

  Frame f=new Frame();

  f addWindowListener(new WindowAdapter()

  public void windowClosing(WindowEvent e)

  System exit( );

  

  );

  f setSize(new Dimension( ));

  f setVisible(true);

  

  public static void main(String[] s)

  new Frame ();

  

  

  Jframe的关闭方法

  setDefaultCloseOperation(EXIT_ON_CLOSE);

  frame的关闭方法如下

  this addWindowListener(new java awt event WindowAdapter()

  public void windowClosing(java awt event WindowEvent e)

  System exit( );

  

cha138/Article/program/Java/hx/201311/27073

相关参考

牛皮癣不宜食用的六种食物

牛皮癣不宜食用的六种食物?牛皮癣的治疗急坏了很多的患者,由于牛皮癣是种慢性的免疫性皮肤病,所以治疗起来见效很慢。专家称,对于牛皮癣的治疗最重要的还是在生活中的饮食,那么牛皮癣不宜食用哪些食物呢?今天我

牛皮癣不宜食用的六种食物

牛皮癣不宜食用的六种食物?牛皮癣的治疗急坏了很多的患者,由于牛皮癣是种慢性的免疫性皮肤病,所以治疗起来见效很慢。专家称,对于牛皮癣的治疗最重要的还是在生活中的饮食,那么牛皮癣不宜食用哪些食物呢?今天我

知识大全 JavaScript全排列的六种算法 具体实现

JavaScript全排列的六种算法具体实现  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  全排

清除池塘野杂鱼的六种方法

野杂鱼在池塘中大量繁殖,既没有商品价值,还会与家鱼争食耗氧,影响池塘养殖产量及经济效益,常用的清除方法有以下六种。1、彻底清塘。鱼苗放养前,抽干池水,用生石灰、强氯精等药物清塘,彻底杀灭野杂鱼、螺,水

清除池塘野杂鱼的六种方法

野杂鱼在池塘中大量繁殖,既没有商品价值,还会与家鱼争食耗氧,影响池塘养殖产量及经济效益,常用的清除方法有以下六种。1、彻底清塘。鱼苗放养前,抽干池水,用生石灰、强氯精等药物清塘,彻底杀灭野杂鱼、螺,水

知识大全 ASP.NET刷新页面的六种方法

ASP.NET刷新页面的六种方法  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  第一privat

经济适用的六种鱼饲料配方

1.适于草鱼或花白鲢。稻草粉70%、豆饼15%、棉饼10%、玉米面5%,另加骨粉1%、食盐0.5%,维生素适量。  2.适于网箱养草鱼。黄豆秸或花生蔓60%、豆饼15%、菜籽饼(或棉籽饼)10%、玉米

经济适用的六种鱼饲料配方

1.适于草鱼或花白鲢。稻草粉70%、豆饼15%、棉饼10%、玉米面5%,另加骨粉1%、食盐0.5%,维生素适量。  2.适于网箱养草鱼。黄豆秸或花生蔓60%、豆饼15%、菜籽饼(或棉籽饼)10%、玉米

玉米秸秆的六种调制方法

一、青贮。有塑料袋青贮和窖式青贮两种,即把收获的青玉米秸秆铡成1~2厘米长小段,并将含水量控制在67%~75%(即以手握原料,从指缝中可见到水珠,但不滴水为宜),装入塑料袋或窖中,压实,密封保存40~

玉米秸秆的六种调制方法

一、青贮。有塑料袋青贮和窖式青贮两种,即把收获的青玉米秸秆铡成1~2厘米长小段,并将含水量控制在67%~75%(即以手握原料,从指缝中可见到水珠,但不滴水为宜),装入塑料袋或窖中,压实,密封保存40~