// Note: this example will show you how broken the focus handling code in
// versions of the JDK earlier than 1.4 (even then...)

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

public class FocusEventExample {
	public static void main (String[] args) {
		Frame frame = new FocusEventFrame("Focus Event Example");
		frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		frame.show();
	}
}

class FocusEventFrame extends Frame
		implements FocusListener
{
	private Label messages = new Label();

	FocusEventFrame(String title) {
		setTitle(title);
		setLayout(new GridLayout(0, 1, 5, 5));
		//setFont(new Font("Ariel", Font.BOLD, 20));

		// put a buncha controls in the frame
		for (int i = 0; i < 5; i++) {
			Button btn = new Button("Button" + String.valueOf(i));
			btn.addFocusListener(this);
			add(btn);
		}

		// Put the debug message label at the bottom
		add(messages);

		// size the frame just right
		pack();
		setSize(500, getHeight());
	}

	public void focusGained(FocusEvent e) {
		messages.setText("focusGained: " + e.getSource());
	}

	public void focusLost(FocusEvent e) {
		//messages.setText("focusLost: " + e.getSource());
	}
}
