Class FocusEvent in Java

0
86
Spread the love
  • 23
  • 34
  • 28
  • 35
  •  
  •  
  •  
  • 12
  •  
  •  
    132
    Shares

Class FocusEvent in Java

An event of this type(FocusEvent) indicates that a Component has gained or lost focus on a temporary or permanent basis. We need to use the inherited getComponent() method to determine which component has gained or lost focus. We need to use getID() to determine the type of focus event; it returns FOCUS_GAINED or FOCUS_LOST.

When the focus is lost, we can call isTemporary() to determine whether it is a temporary loss of focus. Temporary focus loss occurs when the window that contains the component loses focus, for example, or when the focus is temporarily diverted to a popup menu or a scrollbar.

Similarly, we can also use isTemporary() to determine whether the focus is being granted to a component on a temporary basis.

Focus events are generated when a component gets or loses input focus. Focus events come in two flavors, permanent and temporary. Permanent focus events occur with explicit focus changes. For example, when the user tabs through components, this causes permanent focus events. An example of a temporary focus event is when a component loses focus as its containing window is deactivated.

The Class Structure of the FocusEvent is given as

public class java.awt.event.FocusEvent extends java.awt.event.ComponentEvent{
// Public Constructors
public FocusEvent(Component source, int id, boolean temporary);
public FocusEvent(Component source, int id);
// Constants
public static final int FOCUS_FIRST;
public static final int FOCUS_GAINED;
public static final int FOCUS_LAST;
public static final int FOCUS_LOST;
// Public Instance Methods
public boolean isTemporary ();
public String paramString ();// Overrides ComponentEvent
}

The details of the class structure are given as follows:

public final static int FOCUS_FIRST;

public final static int FOCUS_FIRST is a constant that specifies the beginning range of focus event ID values.

public final static int FOCUS_GAINED;

public final static int FOCUS_GAINED is a constant that is an Event type ID indicating that the component gained the input focus.

public final static int FOCUS_LAST;

public final static int FOCUS_LAST is a constant that specifies the ending range of focus event ID values.

public final static int FOCUS_LOST;

public final static int FOCUS_LOST is a constant that that is an Event type ID indicating that the component lost the input focus.

public FocusEvent(Component source, int id);

public FocusEvent(Component source, int id) constructs a non-temporary FocusEvent with the given characteristics.

Parameter
source – The object that generated the event.
id – The event type ID of the event.

public FocusEvent(Component source, int id, boolean temporary);

public FocusEvent(Component source, int id, boolean temporary) constructs a FocusEvent with the given characteristics.

Parameter
source – The object that generated the event.
id – The event type ID of the event.
temporary – A flag indicating whether this is a temporary focus event.

public boolean isTemporary();

public boolean isTemporary() method returns true if this is a temporary focus event; false otherwise.

This method returns true if this is a temporary focus event; false otherwise.

public String paramString();

public String paramString() method is a helper method for toString() to generate string of current settings.

This method returns a String with current settings of the FocusEvent.

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 23
  • 34
  • 28
  • 35
  •  
  •  
  •  
  • 12
  •  
  •  
    132
    Shares

LEAVE A REPLY

Please enter your comment!
Please enter your name here