package CHAPTER11;

import javax.swing.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

// WindowListener 인터페이스를 직접 구현한 클래스
class MyWindowListener implements WindowListener {
    @Override
    public void windowOpened(WindowEvent e) {
        System.out.println("창이 열렸습니다.");
    }
    
    @Override
    public void windowClosing(WindowEvent e) {
        System.out.println("창이 닫힙니다. 프로그램을 종료합니다.");
        System.exit(0);
    }

    @Override
    public void windowClosed(WindowEvent e) {}

    @Override
    public void windowIconified(WindowEvent e) {}

    @Override
    public void windowDeiconified(WindowEvent e) {}

    @Override
    public void windowActivated(WindowEvent e) {}

    @Override
    public void windowDeactivated(WindowEvent e) {}
}

public class WindowListener extends JFrame {
	public WindowListener() {
		setTitle("윈도우 리스너 예제");
		setSize(300, 200);
        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        // 직접 구현한 리스너 클래스 인스턴스를 추가
        addWindowListener(new MyWindowListener());
        setVisible(true);
	}
    public static void main(String[] args) {
        new WindowListener();
    }
}

