Java Swing tutorials.
When keyboard focus is being gained or lost by the component, focus events usually get fired. This is applicable no matter change in focus would be occurring via keyboard, mouse or programmatically.
Here is will be explained that how focus events could be obtained for a component by making a FocusListener instance registered at it. Only for window, focus can be obtained by implementation of the WindowFocusListener instance. For many components implementation of the PropertyChangeListener