Monday, 3 February 2014

Event Classes in java

The classes that represent events are at the core of Java’s event handling mechanism......

Event Classes

The classes that represent events are at the core of Java’s event handling mechanism. At the root of the Java event class hierarchy is EventObject, which is in java.util. EventObject contains two methods: getSource( ) and toString( ). 

The getSource( )method returns the source of the event. Its general form is shown here:

        Object getSource( )

As expected, toString( )returns the string equivalent of the event.The class AWTEvent, defined within the java.awt package, is a subclass of EventObject.It is the superclass (either directly or indirectly) of all AWT-based events used by the delegation event model. Its getID()method can be used to determine the type of the event. 

The signature of this method is shown here:

         int getID()

Main Event Classes in java.awt.event

ActionEvent :
                Generated when a button is pressed, a list item is double-clicked, or a menu item is  selected. 

                Generated when a scroll bar is manipulated.

             Generated when a component is hidden, moved, resized, or becomes visible.

ContainerEvent  :
              Generated when a component is added to or removed from a container.

FocusEvent :
              Generated when a component gains or loses keyboard focus.

InputEvent :
             Abstract superclass for all component input event classes.

ItemEvent :
             Generated when a check box or list item is clicked; also occurs when a choice select is made or   a checkable menu item is selected or deselected.

KeyEvent :
             Generated when input is received from the keyboard.

             Generated when the mouse is dragged, moved, clicked, pressed, or released;also generated when the mouse enters or exits a component.

            Generated when the mouse wheel is moved.

            Generated when the value of a text area or text field is changed.

WindowEvent :
             Generated when a window is activated, closed, deactivated, deiconified,iconified, opened, or quit.

1 comment :

  1. This blog was very useful to understand. I am a fresher i saw a Freshers Jobs in and attended an interview their they asked this question.