3月21日,TestFrame对象是事件源又是监听者,每日20行。

来源:互联网 发布:马赛克拼图软件 编辑:程序博客网 时间:2024/04/30 22:12
import java.awt.*;import java.awt.event.*;public class TestFrame extends Frame implements WindowListener {    public TestFrame(String s) {        super(s);    }    public void windowClosing(WindowEvent e) {        System.out.println("我退出了!");        e.getWindow().setVisible(false);        ((Window)e.getComponent()).dispose();        System.exit(0);    }    public void windowActivated(WindowEvent e) {}    public void windowClosed(WindowEvent e) {}    public void windowDeactivated(WindowEvent e) {}    public void windowDeiconified(WindowEvent e) {}    public void windowIconified(WindowEvent e) {}    public void windowOpened(WindowEvent e) {}    public static void main(String[] args) {        TestFrame f = new TestFrame("A Test Window");        f.setSize(320, 180);        f.setVisible(true);        f.addWindowListener(f);    }}

这里写图片描述
这里写图片描述

0 0
原创粉丝点击