Window を閉じる(WindowListener)

import java.awt.*;
import java.awt.event.*;

public class Test {
	public static void main (String[] args)
	{
		Win win = new Win("Test Window");
	}
}

class Win extends Frame implements WindowListener {
	Win (String name)
	{
					// Frameクラスのコンストラクタ(Windowのタイトルを引き渡す)
		super(name);
					// Windowの大きさ
		setSize(400, 300);
					// ウィンドウを表示
		setVisible(true);
					// イベントリスナ
		addWindowListener(this);
	}

	/************/
	/* 終了処理 */
	/************/
	public void windowClosing(WindowEvent e) {
		System.exit(0);
	}

	/********************************/
	/* イベントリスナの他のメソッド */
	/********************************/
	public void windowActivated(WindowEvent e) {}
	public void windowDeactivated(WindowEvent e) {}
	public void windowOpened(WindowEvent e) {}
	public void windowClosed(WindowEvent e) {}
	public void windowIconified(WindowEvent e) {}
	public void windowDeiconified(WindowEvent e) {}
}