JAVA AWT 事件处理及内部类的实现

来源:互联网 发布:跟黑人做爽吗 知乎 编辑:程序博客网 时间:2024/05/10 16:40


import java.awt.*;
import java.awt.event.*;
public class TestFrame {
 Frame fm = new Frame();

 public void init(){
  
  fm.setSize(300,300);
  Button btn = new Button("ok");
  
  fm.add(btn);
  btn.addActionListener(new ActionListener(){
   public void actionPerformed(ActionEvent e){
     fm.dispose();
    }   
  });
  //fm.addWindowListener(new WindowLisener());
  fm.addWindowListener(new WindowAdapter(){
   public void windowClosing(WindowEvent e){
    fm.setVisible(false);
    fm.dispose();    
   }
  });
  fm.setVisible(true);
  try{
   Thread.sleep(10000);
  }catch(Exception e){}
  fm.dispose();
 }
 public static void main(String[] args) {
  
  TestFrame tf = new TestFrame();
  tf.init(); 
 } 
}

原创粉丝点击