Saturday, 1 February 2014

Event classes:The ActionEvent Class

The ActionEvent Class


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

The ActionEvent class defines four integer constants that can be used to identify any modifiers associated with an action event: 


  • ALT_MASK
  • CTRL_MASK
  • META_MASK
  • SHIFT_MASK
  • ACTION_PERFORMED


ActionEvent has these three constructors:


  • ActionEvent(Objectsrc, int type, String cmd)
  • ActionEvent(Objectsrc, int type, String cmd, int modifiers)
  • ActionEvent(Objectsrc, int type, String cmd, long when, int modifiers)


Here,src is a reference to the object that generated this event. The type of the event is specified by type, and its command string is cmd. The argumentmodifiersindicates which modifier keys (ALT, CTRL, META, and/or SHIFT) were pressed when the event was generated. The when parameter specifies when the event occurred.

 Methods in ActionEvent classes

1) getActionCommand( ) method

You can obtain the command name for the invoking ActionEvent object by using the getActionCommand( ) method, shown here:

String getActionCommand( )

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) getModifiers( ) method:

The getModifiers( ) method returns a value that indicates which modifier keys (ALT, CTRL,META, and/or SHIFT) were pressed when the event was generated. Its form is shown here:

int getModifiers( )

3) getWhen( ) method:

The method getWhen( )returns the time at which the event took place. This is called the event’s timestamp. The getWhen( ) method is shown here:

long getWhen( )











































































No comments:

Post a Comment