FrameDemo1

package cn.itcast;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
//import java.awt.event.WindowListener;
public class FrameDemo1 {
 public static void main(String[] args) {
  // 创建窗体对象
  Frame f = new Frame("窗体关闭!");
  
  //设置窗体属性
  f.setBounds(400, 200, 400, 300);
  
  //事件监听
  /*
   * 事件源
   * 事件
   * 事件处理
   * 事件监听
   */
//  f.addWindowListener(new WindowListener() {
//   
//   @Override
//   public void windowOpened(WindowEvent e) {
//    // TODO Auto-generated method stub
//    
//   }
//   
//   @Override
//   public void windowIconified(WindowEvent e) {
//    // TODO Auto-generated method stub
//    
//   }
//   
//   @Override
//   public void windowDeiconified(WindowEvent e) {
//    // TODO Auto-generated method stub
//    
//   }
//   
//   @Override
//   public void windowDeactivated(WindowEvent e) {
//    // TODO Auto-generated method stub
//    
//   }
//   
//   @Override
//   public void windowClosing(WindowEvent e) {
//    // TODO Auto-generated method stub
//    System.exit(0);//退出虚拟机
//    
//   }
//   
//   @Override
//   public void windowClosed(WindowEvent e) {
//    // TODO Auto-generated method stub
//   }
//   
//   @Override
//   public void windowActivated(WindowEvent e) {
//    // TODO Auto-generated method stub
//    
//   }
//  });
  //用适配器类改进
  //用于接收窗口事件的侦听器接口
  f.addWindowListener(new WindowAdapter() {
   @Override
   public void windowClosing(WindowEvent e) {
    System.exit(0);//关闭虚拟机
   }
  });
  //设置窗体可见
  f.setVisible(true);
  
 }
}
posted @ 2018-11-02 09:09  阿蓉  阅读(184)  评论(0编辑  收藏  举报