Example usage for java.awt.event FocusEvent FOCUS_FIRST

List of usage examples for java.awt.event FocusEvent FOCUS_FIRST

Introduction

In this page you can find the example usage for java.awt.event FocusEvent FOCUS_FIRST.

Prototype

int FOCUS_FIRST

To view the source code for java.awt.event FocusEvent FOCUS_FIRST.

Click Source Link

Document

The first number in the range of ids used for focus events.

Usage

From source file:Main.java

public static void main(String[] a) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextField textField = new JTextField("A TextField");
    textField.addFocusListener(new FocusListener() {
        public void focusGained(FocusEvent e) {
            displayMessage("Focus gained", e);
        }//from w  w  w .  j a  v  a2 s. c  om

        public void focusLost(FocusEvent e) {
            displayMessage("Focus lost", e);
        }

        void displayMessage(String prefix, FocusEvent e) {
            System.out.println(e.getID() == FocusEvent.FOCUS_FIRST);
        }
    });
    frame.add(textField, "North");
    frame.add(new JTextField(), "South");
    frame.setSize(300, 200);
    frame.setVisible(true);
}