FocusEvent class in java.awt.event package: Integer constants, Types of constructors, Methods

FocusEvent class in java.awt.event package is used for handling events created when a component gets or loses keyboard focus. It is a sub class of ComponentEvent class.

Integer constants defined by FocusEvent class:

  • FOCUS_GAINED: When focus is gained.
  • FOCUS_LOST: When focus is lost.

Types of constructors defined by FocusEvent class:

Type-1: By using source and type of event.

FocusEvent(Component src, int type)

Type-2: By using source, type of event and temporary flag.

FocusEvent(Component src, int type, boolean tempflag)

Type-3: By using source, type of event, temporary flag, and opposite component. For a FOCUS_GAINED event, opp will refer to component which has lost its focus and for a FOCUS_LOST event, opp will refer to component which has gained focus.

Focus Event(Component src, int type, boolean tempoflag, Component opp)

Methods defined by FocusEvent class:

getOppositeComponent( ) method: It is used to return the opposite component.


Component getOppositeComponent( )

isTemporary( ) method: It shows that change in focus is temporary.


boolean isTemporary( )

Leave a Reply