GUI-监听器的使用及WindowAdapter

import java.awt.*;
import java.awt.event.*;
public class first {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Frame f = new Frame("my awt");
        f.setSize(500, 300);
        f.setLocation(300,100);
        f.setLayout(new FlowLayout());
        f.addWindowListener(new WindowAdapter() 
        {
            public void windowClosing(WindowEvent e)
            {
                System.out.println("我关");
                System.exit(0);
            }
        }
                );
    //    f.addWindowListener(new MyWin());
        Button b = new Button("我是一个按钮");
        f.add(b);
        
        
        f.setVisible(true);
        System.out.println("Hello World!!");
        
    }

}

class MyWin extends WindowAdapter
{
    public void windowClosing(WindowEvent e)
    {
        System.out.println("window closing");
    }
}

123

posted @ 2019-11-11 10:25  蚂蚁雅黑1010  阅读(185)  评论(0编辑  收藏  举报