com.internationalnetwork.gui
Class JListenerEvent

Object
  extended by com.internationalnetwork.gui.JListenerEvent

public class JListenerEvent
extends Object

The JListenerEvent class stores one of four different types of events, which do not all belong to the same superclass (but it sure would have been handy if they were because then we wouldn't have needed to create this class).


Field Summary
static String VERSION
          Version number of this Package (read-only).
 
Constructor Summary
JListenerEvent(java.awt.event.ActionEvent event)
          Create a new JListenerEvent object.
JListenerEvent(java.awt.event.KeyEvent event)
          Create a new JListenerEvent object.
JListenerEvent(java.awt.event.MouseEvent event)
          Create a new JListenerEvent object.
JListenerEvent(java.awt.event.WindowEvent event)
          Create a new JListenerEvent object.
 
Method Summary
 boolean consume()
          Consumes the event by calling its respective consume() method.
 java.awt.event.ActionEvent getActionEvent()
          Gets the ActionEvent, as it was stored in its original form.
 java.awt.AWTEvent getAWTEvent()
          Gets the event using the closest possible super-class.
 int getID()
          Returns the event ID constant.  This is the constant value that is defined in the respective Event class documentation, and it's important to note that there are some overlapping values between the different types of events so you must determine the event type first.
 java.awt.event.KeyEvent getKeyEvent()
          Gets the KeyEvent, as it was stored in its original form.
 java.awt.event.MouseEvent getMouseEvent()
          Gets the MouseEvent, as it was stored in its original form.
 Object getSource()
          Returns the object on which the Event initially occurred.  Although this will usually be a Component, there is no guarantee about this, so the java.lang.Object type is returned instead (you will have to re-cast it on your own).
 char getType()
          Returns the event type, represented by a primitive "char" so that the developer may conveniently use switch(getEventType()) to handle the different event types.
 java.awt.event.WindowEvent getWindowEvent()
          Gets the WindowEvent, as it was stored in its original form.
 boolean isActionEvent()
          Indicates if this event holds an ActionEvent.
 boolean isKeyEvent()
          Indicates if this event holds a KeyEvent.
 boolean isMouseEvent()
          Indicates if this event holds a MouseEvent.
 boolean isWindowEvent()
          Indicates if this event holds a WindowEvent.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final String VERSION
Version number of this Package (read-only).

See Also:
Constant Field Values
Constructor Detail

JListenerEvent

public JListenerEvent(java.awt.event.ActionEvent event)
Create a new JListenerEvent object.

Parameters:
event - The event object

JListenerEvent

public JListenerEvent(java.awt.event.KeyEvent event)
Create a new JListenerEvent object.

Parameters:
event - The event object

JListenerEvent

public JListenerEvent(java.awt.event.MouseEvent event)
Create a new JListenerEvent object.

Parameters:
event - The event object

JListenerEvent

public JListenerEvent(java.awt.event.WindowEvent event)
Create a new JListenerEvent object.

Parameters:
event - The event object
Method Detail

consume

public boolean consume()
Consumes the event by calling its respective consume() method.

Only KeyEvent and MouseEvent events can be consumed, and FALSE will be returned if other attempts to consume events for event classes that don't support consume() are called.

Returns:
boolean - TRUE indicates that the event was consumed; FALSE otherwise

getActionEvent

public java.awt.event.ActionEvent getActionEvent()
Gets the ActionEvent, as it was stored in its original form.

Returns:
ActionEvent - if this is the wrong type, then NULL will be returned

getAWTEvent

public java.awt.AWTEvent getAWTEvent()
Gets the event using the closest possible super-class.

Returns:
AWTEvent - the event object casted as an AWTEvent object

getID

public int getID()
Returns the event ID constant.  This is the constant value that is defined in the respective Event class documentation, and it's important to note that there are some overlapping values between the different types of events so you must determine the event type first.

An example of usage for checking for a certain type of WindowEvent would be to use the appropriate constant as follows:

1: if ('w' == jListener.getType()) { // WindowEvent
2:
3:   if (WindowEvent.WINDOW_CLOSING == jListener.getID()) {
4:
5:     // Window close event handling code goes here...
6:
7:   } // -x- if WINDOW_CLOSING -x-
8:
9: } // -x- if WindowEvent -x-

For a different type of event, such as a KeyEvent, you would chaneg the reference to the "WindowEvent" class to "KeyEvent" (see the appropriate documentation in your JDK for complete lists of event constants).

Returns:
int - Event ID constant

getKeyEvent

public java.awt.event.KeyEvent getKeyEvent()
Gets the KeyEvent, as it was stored in its original form.

Returns:
KeyEvent - if this is the wrong type, then NULL will be returned

getMouseEvent

public java.awt.event.MouseEvent getMouseEvent()
Gets the MouseEvent, as it was stored in its original form.

Returns:
MouseEvent - if this is the wrong type, then NULL will be returned

getSource

public Object getSource()
Returns the object on which the Event initially occurred.  Although this will usually be a Component, there is no guarantee about this, so the java.lang.Object type is returned instead (you will have to re-cast it on your own).

Returns:
Object - The object on which the Event initially occurred, which is derived from the appropriate getSource() method from the respective ActionEvent, KeyEvent, MouseEvent, or WindowEvent

getType

public char getType()
Returns the event type, represented by a primitive "char" so that the developer may conveniently use switch(getEventType()) to handle the different event types.

Returns:
char - One of the following characters:
  • a - ActionEvent
  • k - KeyEvent
  • m - MouseEvent
  • w - WindowEvent

getWindowEvent

public java.awt.event.WindowEvent getWindowEvent()
Gets the WindowEvent, as it was stored in its original form.

Returns:
WindowEvent - if this is the wrong type, then NULL will be returned

isActionEvent

public boolean isActionEvent()
Indicates if this event holds an ActionEvent.


isKeyEvent

public boolean isKeyEvent()
Indicates if this event holds a KeyEvent.


isMouseEvent

public boolean isMouseEvent()
Indicates if this event holds a MouseEvent.


isWindowEvent

public boolean isWindowEvent()
Indicates if this event holds a WindowEvent.