This section contains the detail about the Event Classes in java Swing.
Event Classes
Java has a number of classes that describe different categories of events. The following figure shows the hierarchy of a Java event class :
The Action Event class
? ActionEvent is generated by an AWT component, such as a button, when a
component-specific action is performed.
? The action event is generated when a button is pressed, a list item is
double-clicked, or a menu item is selected.
? The following syntax shows the declaration of the constructor of the
ActionEvent class is:
public ActionEvent(Object source, int id, String command)
? The main methods included in the Action Event class are:
? String getActionCommand
The MouseEvent class
? The MouseEvent class extends the java.awt.event.InputEvent class.
? The mouse event indicates that a mouse action has occurred on a component.
? The mouse events include:
? Pressing a mouse button
? Releasing a mouse button
? Clicking a mouse button
? Entering of mouse in a component area
? Exiting of mouse from a component area
? The mouse event class defines some integer constants that can be used to
identify several types of mouse events.
Given below the various integer constants of the Event class :
Constants | Description |
MOUSE_CLICKED | Identifies the event of mouse clicking. |
MOUSE_DRAGGED | Identifies the event of dragging of mouse. |
MOUSE_MOVED | Identifies the event of mouse moving. |
MOUSE_PRESSED | Identifies the event of mouse pressing. |
MOUSE_RELEASED | Identifies the event of mouse releasing. |
MOUSE_ENTERED | Identifies the event of mouse entering an AWT component. |
MOUSE_EXITED | Identifies the event of mouse exiting an AWT component. |
Given below Various methods of the MouseEvent class :
Methods | Description |
public int getX() | Returns the horizontal x coordinate of the mouse position relative to a source component. |
public int getY() | Returns the vertical y coordinate of the mouse position relative to a source component. |
public point getPoint() | Returns the Point object. The Point object contains the x and y coordinates of the mouse position relative to a source component. |
public void translatePoint(int x, int y) | Translates the coordinates of a mouse event to a new position by adding x and y offsets. |
public int getClickCount() | Returns the number of mouse clicks associated with an event. |
[ 0 ] Comments