public class

InvocationEvent

extends AWTEvent
implements ActiveEvent
java.lang.Object
   ↳ java.util.EventObject
     ↳ java.awt.AWTEvent
       ↳ java.awt.event.InvocationEvent
Known Direct Subclasses

Class Overview

An event which executes the run() method on a Runnable when dispatched by the AWT event dispatcher thread. This class can be used as a reference implementation of ActiveEvent rather than declaring a new class and defining dispatch().

Instances of this class are placed on the EventQueue by calls to invokeLater and invokeAndWait. Client code can use this fact to write replacement functions for invokeLater and invokeAndWait without writing special-case code in any AWTEventListener objects.

Summary

Constants
int INVOCATION_DEFAULT The default id for all InvocationEvents.
int INVOCATION_FIRST Marks the first integer id for the range of invocation event ids.
int INVOCATION_LAST Marks the last integer id for the range of invocation event ids.
[Expand]
Inherited Constants
From class java.awt.AWTEvent
Fields
protected boolean catchExceptions Set to true if dispatch() catches Throwable and stores it in the exception instance variable.
protected Object notifier The (potentially null) Object whose notifyAll() method will be called immediately after the Runnable.run() method returns.
protected Runnable runnable The Runnable whose run() method will be called.
[Expand]
Inherited Fields
From class java.awt.AWTEvent
From class java.util.EventObject
Public Constructors
InvocationEvent(Object source, Runnable runnable)
Constructs an InvocationEvent with the specified source which will execute the runnable's run method when dispatched.
InvocationEvent(Object source, Runnable runnable, Object notifier, boolean catchThrowables)
Constructs an InvocationEvent with the specified source which will execute the runnable's run method when dispatched.
Protected Constructors
InvocationEvent(Object source, int id, Runnable runnable, Object notifier, boolean catchThrowables)
Constructs an InvocationEvent with the specified source and ID which will execute the runnable's run method when dispatched.
Public Methods
void dispatch()
Executes the Runnable's run() method and notifies the notifier (if any) when run() returns.
Exception getException()
Returns any Exception caught while executing the Runnable's run() method.
Throwable getThrowable()
Returns any Throwable caught while executing the Runnable's run() method.
long getWhen()
Returns the timestamp of when this event occurred.
String paramString()
Returns a parameter string identifying this event.
[Expand]
Inherited Methods
From class java.awt.AWTEvent
From class java.util.EventObject
From class java.lang.Object
From interface java.awt.ActiveEvent

Constants

public static final int INVOCATION_DEFAULT

The default id for all InvocationEvents.

Constant Value: 1200 (0x000004b0)

public static final int INVOCATION_FIRST

Marks the first integer id for the range of invocation event ids.

Constant Value: 1200 (0x000004b0)

public static final int INVOCATION_LAST

Marks the last integer id for the range of invocation event ids.

Constant Value: 1200 (0x000004b0)

Fields

protected boolean catchExceptions

Set to true if dispatch() catches Throwable and stores it in the exception instance variable. If false, Throwables are propagated up to the EventDispatchThread's dispatch loop.

protected Object notifier

The (potentially null) Object whose notifyAll() method will be called immediately after the Runnable.run() method returns.

protected Runnable runnable

The Runnable whose run() method will be called.

Public Constructors

public InvocationEvent (Object source, Runnable runnable)

Constructs an InvocationEvent with the specified source which will execute the runnable's run method when dispatched.

This is a convenience constructor. An invocation of the form InvocationEvent(source, runnable) behaves in exactly the same way as the invocation of InvocationEvent(source, runnable, null, false).

This method throws an IllegalArgumentException if source is null.

Parameters
source the Object that originated the event
runnable the Runnable whose run method will be executed
Throws
IllegalArgumentException if source is null

public InvocationEvent (Object source, Runnable runnable, Object notifier, boolean catchThrowables)

Constructs an InvocationEvent with the specified source which will execute the runnable's run method when dispatched. If notifier is non-null, notifyAll() will be called on it immediately after run returns.

An invocation of the form InvocationEvent(source, runnable, notifier, catchThrowables) behaves in exactly the same way as the invocation of InvocationEvent(source, InvocationEvent.INVOCATION_DEFAULT, runnable, notifier, catchThrowables).

This method throws an IllegalArgumentException if source is null.

Parameters
source the Object that originated the event
runnable the Runnable whose run method will be executed
notifier the Object whose notifyAll method will be called after Runnable.run has returned
catchThrowables specifies whether dispatch should catch Throwable when executing the Runnable's run method, or should instead propagate those Throwables to the EventDispatchThread's dispatch loop
Throws
IllegalArgumentException if source is null

Protected Constructors

protected InvocationEvent (Object source, int id, Runnable runnable, Object notifier, boolean catchThrowables)

Constructs an InvocationEvent with the specified source and ID which will execute the runnable's run method when dispatched. If notifier is non-null, notifyAll will be called on it immediately after run returns.

Note that passing in an invalid id results in unspecified behavior. This method throws an IllegalArgumentException if source is null.

Parameters
source the Object that originated the event
id the ID for the event
runnable the Runnable whose run method will be executed
notifier the Object whose notifyAll method will be called after Runnable.run has returned
catchThrowables specifies whether dispatch should catch Throwable when executing the Runnable's run method, or should instead propagate those Throwables to the EventDispatchThread's dispatch loop
Throws
IllegalArgumentException if source is null

Public Methods

public void dispatch ()

Executes the Runnable's run() method and notifies the notifier (if any) when run() returns.

public Exception getException ()

Returns any Exception caught while executing the Runnable's run() method.

Returns
  • A reference to the Exception if one was thrown; null if no Exception was thrown or if this InvocationEvent does not catch exceptions

public Throwable getThrowable ()

Returns any Throwable caught while executing the Runnable's run() method.

Returns
  • A reference to the Throwable if one was thrown; null if no Throwable was thrown or if this InvocationEvent does not catch Throwables

public long getWhen ()

Returns the timestamp of when this event occurred.

Returns
  • this event's timestamp

public String paramString ()

Returns a parameter string identifying this event. This method is useful for event-logging and for debugging.

Returns
  • A string identifying the event and its attributes