其他分享
首页 > 其他分享> > 窗口监听事件

窗口监听事件

作者:互联网

package com.jia.lesson;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class TestWindow {
    public static void main(String[] args) {
        new WindowFrame();
    }
}

class WindowFrame extends Frame {
    public WindowFrame() {
        setVisible(true);
        setBackground(Color.GREEN);
        setBounds(100, 100, 200, 200);
        //addWindowListener(new MyWindowListener());

        this.addWindowListener(
                //匿名内部类
                new WindowAdapter() {

                    //关闭窗口
                    @Override
                    public void windowClosing(WindowEvent e) {
                        System.out.println("windowClosing");
                    }

                    //激活窗口
                    @Override
                    public void windowActivated(WindowEvent e) {
                        WindowFrame source =(WindowFrame)e.getSource();
                        source.setTitle("被激活了");
                        System.out.println("windowActivated");
                    }
                }
        );
    }
}

标签:窗口,void,new,监听,事件,WindowEvent,WindowFrame,java,public
来源: https://blog.csdn.net/qq_49759937/article/details/120597662