FocusEvent クラス

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

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

/*******************/
/* クラスWinの定義 */
/*******************/
class Win extends Frame implements FocusListener {

	TextArea ta;
	TextField tx1, tx2;

	/******************/
	/* コンストラクタ */
	/******************/
	Win (String name)
	{
					// Frameクラスのコンストラクタ(Windowのタイトルを引き渡す)
		super(name);
					// レイアウトの変更(行,列,水平ギャップ,垂直ギャップ)
		setLayout(new GridLayout(2, 1, 5, 10));
		Font f = new Font("MS 明朝", Font.BOLD, 20);
					// 上のパネル
						// パネルの追加
		Panel pn1 = new Panel();
		add(pn1);
						// テキストフィールドの追加
		tx1 = new TextField("Text Field 1");
		tx1.setFont(f);
		tx1.addFocusListener(this);
		pn1.add(tx1);

		tx2 = new TextField("Text Field 2");
		tx2.setFont(f);
		tx2.addFocusListener(this);
		pn1.add(tx2);
					// 下のパネル
						// パネルの追加
		Panel pn2 = new Panel();
		add(pn2);
						// テキストエリアの追加
		ta = new TextArea(4, 25);
		ta.setFont(f);
		pn2.add(ta);
					// Windowの大きさ
		setSize(320, 300);
					// ウィンドウを表示
		setVisible(true);
					// イベントアダプタ
		addWindowListener(new WinEnd());
	}

	/******************************/
	/* 上,左,下,右の余白の設定 */
	/******************************/
	public Insets getInsets()
	{
		return new Insets(35, 10, 10, 10);
	}

	/********************/
	/* フォーカスの状態 */
	/********************/
	public void focusGained(FocusEvent e)
	{
		if (e.getSource() == tx1)
			ta.append("Text Field 1 : 入力可能\n");
		if (e.getSource() == tx2)
			ta.append("Text Field 2 : 入力可能\n");
	}
	public void focusLost(FocusEvent e)
	{
		if (e.getSource() == tx1)
			ta.append("Text Field 1 : 入力不可\n");
		if (e.getSource() == tx2)
			ta.append("Text Field 2 : 入力不可\n");
	}

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