Java关闭窗体方法总结

Java关闭窗体方法总结

ID:40749586

大小:34.00 KB

页数:4页

时间:2019-08-07

Java关闭窗体方法总结_第1页
Java关闭窗体方法总结_第2页
Java关闭窗体方法总结_第3页
Java关闭窗体方法总结_第4页
资源描述:

《Java关闭窗体方法总结》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、Java关闭窗体方法总结 1.使用JFrame的enableEvents和processWindowEvent  //Frame1.java  importjava.awt.*;  importjava.awt.event.*;  importjavax.swing.*;  publicclassFrame1extendsJFrame{  publicFrame1(){  enableEvents(AWTEvent.WINDOW_EVENT_MASK);  this.setSize(newDimen

2、sion(400,300));  this.setTitle("Frame1");  }  protectedvoidprocessWindowEvent(WindowEvente){  super.processWindowEvent(e);  if(e.getID()==WindowEvent.WINDOW_CLOSING){  System.exit(0);  }  }  }  2.直接实现WindowListener接口  //Frame1.java  importjava.awt.*;  

3、importjava.awt.event.*;  publicclassFrame1extendsFrameimplementsWindowListener{  publicFrame1(){  this.setSize(newDimension(400,300));  this.setTitle("Frame1");  this.addWindowListener(this);  }  publicvoidwindowClosing(WindowEventwindowEvent){  System

4、.exit(0);  }  publicvoidwindowOpened(WindowEventwindowEvent){}  publicvoidwindowClosed(WindowEventwindowEvent){}  publicvoidwindowIconified(WindowEventwindowEvent){}  publicvoidwindowDeiconified(WindowEventwindowEvent){}  publicvoidwindowActivated(Wind

5、owEventwindowEvent){}  publicvoidwindowDeactivated(WindowEventwindowEvent){}  }  3.直接继承窗体适配器WindowAdapter  //Frame1.java  importjava.awt.*;  importjava.awt.event.*;  publicclassFrame1extendsWindowAdapter{  publicFrame1(){  Framef=newFrame();  f.setSize

6、(newDimension(400,300));  f.setTitle("Frame1");  f.addWindowListener(this);  f.setVisible(true);  }  publicstaticvoidmain(String[]s){  newFrame1();  }  publicvoidwindowClosing(WindowEventwindowEvent){  System.exit(0);  }  }  4.间接继承窗体适配器WindowAdapter  /

7、/Frame1.java  importjava.awt.*;  importjava.awt.event.*;  publicclassFrame1extendsFrame{  publicFrame1(){  this.setSize(newDimension(400,300));  this.setTitle("Frame1");  this.addWindowListener(newwinAdapter());  this.setVisible(true);  }  publicstatic

8、voidmain(String[]s){  newFrame1();  }  }  classwinAdapterextendsWindowAdapter{  publicvoidwindowClosing(WindowEventwindowEvent){  System.exit(0);  }  }  5.间接实现WindowListener接口 //Frame1.java  importjava.awt.*;  importjava.awt.event.*;  p

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。