3.2. Event classes :
• Event classes are the responsible for handling
events in the event handling mechanism.
• All the listeners and its methods are also
encapsulated with event classes.
• All the event classes are present under
java.awt.event package.
• EventObject class it is the root class from which
all event state objects shall be derived.
• It is the superclass of all events.
• All events are constructed with a reference to the object.
• The EventObject class is at the top/root of the Java event
class hierarchy.
• It belongs to the java.util package. and other event
classes are present in java.awt.event package.
EventObject class constructor is:
EventObject (Object src)
• Here, src is the objects that generates the event.
EventObject class Methods :
The getSource() and toString() are the methods of the
EventObject class.
1. getSource( )
The getSource( ) method returns the source of the
event.
• Its general form is shown here:
Object getSource( )
2. toString( )
toString( ) returns the string equivalent of the event.
• There is getID( ) method belonging to java.awt.event
package returns the nature of the event. Or can be used to
determine the type of the event.
• Syntax is,
int getID( )
• The main classes in java.awt.event: Provides interfaces
and classes for dealing with different types of events
fired by AWT components.
Table :Event classes.
Event classes :
1. ActionEvent Class.
2. ItemEvent Class.
3. KeyEvent Class.
4. MouseEvent Class.
5. TextEvent Class.
6. WindowEvent Class.
1. ActionEvent Class :
The ActionEvent class defines four integer constants
that can be used to identify any modifiers associated
with an action event :
1. ALT_MASK,
2. CTRL_MASK,
3. META_MASK,
4. SHIFT_MASK.
There is integer constant ACTION_PERFORMED
which can be used to identify action events.
ActionEvent has three constructors :
1. ActionEvent (Object src, int type, String cmd)
2. ActionEvent (Object src, int type, String cmd,
int modifiers)
3. ActionEvent (Object src, int type, String cmd,
long when, int modifiers)
ActionEvent Methods:
1. String getActionCommand() :
This method is useful for obtaining the Command
string which is specified during the generation of event. For
example, when a button is pressed, an action event is
generated that has a command name equal to the label on that
button.
2. The getModifier() :
This method returns the value which indicates the
type of key being pressed at the time of event.
3. int getWhen() :
The getWhen() method returns the time at which the
event occurs.
2. ItemEvent Class :
There are two types of item events which are
identified by two integer constants :
ItemEvent defiens one integer constant,
ITEM_STATE_CHANGED that signifies a change of state.
ItemEvent uses the constructor:
1. ItemEvent (ItemSelectable src, int type, Object entry, int
state)
DESELECTED The user deselected an item.
SELECTED The user selected an item.
ItemEvent Methods :
1. The getItem() :
returns a reference to the item that generated an
event.
2. ItemSelectable getItemSelectable() :
The getItemSelectable() method returns a reference to
the ItemSelectable object that generated an event.
3. Int getStateChange() :
The getStateChange() method returns the state
change(i.e, SELECTED or DESELECTED) for an event.
Thank you

AJP Event classes.pptx

  • 1.
    3.2. Event classes: • Event classes are the responsible for handling events in the event handling mechanism. • All the listeners and its methods are also encapsulated with event classes. • All the event classes are present under java.awt.event package. • EventObject class it is the root class from which all event state objects shall be derived. • It is the superclass of all events.
  • 2.
    • All eventsare constructed with a reference to the object. • The EventObject class is at the top/root of the Java event class hierarchy. • It belongs to the java.util package. and other event classes are present in java.awt.event package. EventObject class constructor is: EventObject (Object src) • Here, src is the objects that generates the event.
  • 3.
    EventObject class Methods: The getSource() and toString() are the methods of the EventObject class. 1. getSource( ) The getSource( ) method returns the source of the event. • Its general form is shown here: Object getSource( ) 2. toString( ) toString( ) returns the string equivalent of the event.
  • 4.
    • There isgetID( ) method belonging to java.awt.event package returns the nature of the event. Or can be used to determine the type of the event. • Syntax is, int getID( ) • The main classes in java.awt.event: Provides interfaces and classes for dealing with different types of events fired by AWT components.
  • 5.
  • 6.
    Event classes : 1.ActionEvent Class. 2. ItemEvent Class. 3. KeyEvent Class. 4. MouseEvent Class. 5. TextEvent Class. 6. WindowEvent Class.
  • 7.
    1. ActionEvent Class: The ActionEvent class defines four integer constants that can be used to identify any modifiers associated with an action event : 1. ALT_MASK, 2. CTRL_MASK, 3. META_MASK, 4. SHIFT_MASK. There is integer constant ACTION_PERFORMED which can be used to identify action events.
  • 8.
    ActionEvent has threeconstructors : 1. ActionEvent (Object src, int type, String cmd) 2. ActionEvent (Object src, int type, String cmd, int modifiers) 3. ActionEvent (Object src, int type, String cmd, long when, int modifiers)
  • 9.
    ActionEvent Methods: 1. StringgetActionCommand() : This method is useful for obtaining the Command string which is specified during the generation of event. For example, when a button is pressed, an action event is generated that has a command name equal to the label on that button. 2. The getModifier() : This method returns the value which indicates the type of key being pressed at the time of event. 3. int getWhen() : The getWhen() method returns the time at which the event occurs.
  • 10.
    2. ItemEvent Class: There are two types of item events which are identified by two integer constants : ItemEvent defiens one integer constant, ITEM_STATE_CHANGED that signifies a change of state. ItemEvent uses the constructor: 1. ItemEvent (ItemSelectable src, int type, Object entry, int state) DESELECTED The user deselected an item. SELECTED The user selected an item.
  • 11.
    ItemEvent Methods : 1.The getItem() : returns a reference to the item that generated an event. 2. ItemSelectable getItemSelectable() : The getItemSelectable() method returns a reference to the ItemSelectable object that generated an event. 3. Int getStateChange() : The getStateChange() method returns the state change(i.e, SELECTED or DESELECTED) for an event.
  • 12.