java事件演示

package cn.stat.p3.windowdemo;

import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class windowdemo {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        //创建窗体
        Frame f=new Frame("my frame");
        //设置大小
        f.setSize(200,200);
        //创建按钮
        Button but=new Button("yige");
        f.setLayout(new FlowLayout());//设置窗体流布局
        //添加按钮
        f.add(but);
        //添加窗体事件监听
        f.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                // TODO Auto-generated method stub
            
                System.out.println("dddd");
                System.exit(0);//关闭
            }

            
        });
        
        //添加按钮监听
        but.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                // TODO Auto-generated method stub
                System.out.println("dddd");
                System.exit(0);//关闭
            }
        });
        //显示窗体
        f.setVisible(true);
        
        
        
        System.out.println("over");
        
        

    }

}

 

posted @ 2015-09-06 15:57  自由无风  阅读(217)  评论(0编辑  收藏  举报