Wednesday, 5 February 2014

Event classes:The FocusEvent Class

 FocusEvent :gains or loses input focus.......

The FocusEvent Class

         A FocusEvent is generated when a component gains or loses input focus. 

Integer constants :


 FocusEvent Constructor:

FocusEvent is a subclass of ComponentEvent and has these constructors:

  • FocusEvent(Componentsrc, int type)
  • FocusEvent(Componentsrc, int type, boolean temporaryFlag)
  • FocusEvent(Componentsrc, int type, boolean temporaryFlag, Component other)

Here,src is a reference to the component that generated this event. The type of the event is specified by type. The argument temporaryFlag is set to true if the focus event is temporary.Otherwise, it is set to false.

Focus Events:

The other component involved in the focus change, called the opposite component, is passed in other. 


                    FOCUS_GAINED event occurred, other will refer to the component that lost focus.


                   FOCUS_LOSTevent occurred, other will refer to the component that gains focus.

Methods in FocusEvent class

  • getOppositeComponent( ):

          The opposite component is returned.Its form is shown here:

                            Component getOppositeComponent( )

  •  isTemporary( ) method:

         The isTemporary( ) method indicates if this focus change is temporary. Its form is shown here:

                     boolean isTemporary( )

The method returns true if the change is temporary. Otherwise, it returns false

No comments :

Post a comment