Module javafx.base
Package javafx.event

# Class Event

java.lang.Object
java.util.EventObject
javafx.event.Event

All Implemented Interfaces:
  `Serializable`, `Cloneable`

Direct Known Subclasses:
  `ActionEvent`, `CheckBoxTreeItem.TreeModificationEvent`, `DialogEvent`, `InputEvent`, `ListView.EditEvent`, `MediaErrorEvent`, `ScrollToEvent`, `SortEvent`, `TableColumn.CellEditEvent`, `TransformChangedEvent`, `TreeItem.TreeModificationEvent`, `TreeTableColumn.CellEditEvent`, `TreeTableView.EditEvent`, `TreeView.EditEvent`, `WebErrorEvent`, `WebEvent`, `WindowEvent`, `WorkerStateEvent`

public class Event extends EventObject implements Cloneable
Base class for FX events. Each FX event has associated an event source, event target and an event type. The event source specifies for an event handler the object on which that handler has been registered and which sent the event to it. The event target defines the path through which the event will travel when posted. The event type provides additional classification to events of the same `Event` class.

Since:
  JavaFX 2.0
See Also:
  - Serialized Form

## Field Summary

Fields
Modifier and Type
Field
Description
`static final EventType<Event>`
`ANY`
Common supertype for all event types.
`protected boolean`
`consumed`
Whether this event has been consumed by any filter or handler.
`protected EventType<? extends Event>`
`eventType`
Type of the event.
`static final EventTarget`
`NULL_SOURCE_TARGET`
The constant which represents an unknown event source / target.
`protected EventTarget`
`target`
Event target that defines the path through which the event will travel when posted.

### Fields inherited from class java.util.EventObject

`source`

## Constructor Summary

Constructors
Constructor
Description
`Event(Object source, EventTarget target, EventType<? extends Event> eventType)`
Construct a new `Event` with the specified event source, target and type.
`Event(EventType<? extends Event> eventType)`
Construct a new `Event` with the specified event type.

## Method Summary

Modifier and Type
Method
Description
`Object`
`clone()`
Creates and returns a copy of this `Event`.
`void`
`consume()`
Marks this `Event` as consumed.
`Event`
`copyFor(Object newSource, EventTarget newTarget)`
Creates and returns a copy of this event with the specified event source and target.
`static void`
`fireEvent(EventTarget eventTarget, Event event)`
Fires the specified event.
`EventType<? extends Event>`
`getEventType()`
Gets the event type of this event.
`EventTarget`
`getTarget()`
Returns the event target of this event.
`boolean`
`isConsumed()`
Indicates whether this `Event` has been consumed by any filter or handler.

### Methods inherited from class java.util.EventObject

`getSource, toString`

### Methods inherited from class java.lang.Object

`equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Field Details

### NULL_SOURCE_TARGET

public static final EventTarget NULL_SOURCE_TARGET
The constant which represents an unknown event source / target.

### ANY

public static final EventType<Event> ANY
Common supertype for all event types.

### eventType

protected EventType<? extends Event> eventType
Type of the event.

### target

protected transient EventTarget target
Event target that defines the path through which the event will travel when posted.

### consumed

protected boolean consumed
Whether this event has been consumed by any filter or handler.

## Constructor Details

### Event

public Event(EventType<? extends Event> eventType)
Construct a new `Event` with the specified event type. The source and target of the event is set to `NULL_SOURCE_TARGET`.

Parameters:
  `eventType` - the event type

### Event

public Event(Object source, EventTarget target, EventType<? extends Event> eventType)
Construct a new `Event` with the specified event source, target and type. If the source or target is set to `null`, it is replaced by the `NULL_SOURCE_TARGET` value.

Parameters:
  `source` - the event source which sent the event
  `target` - the event target to associate with the event
  `eventType` - the event type

## Method Details

### getTarget

public EventTarget getTarget()
Returns the event target of this event. The event target specifies the path through which the event will travel when posted.

Returns:
  the event target

### getEventType

public EventType<? extends Event> getEventType()
Gets the event type of this event. Objects of the same `Event` class can have different event types. These event types further specify what kind of event occurred.

Returns:
  the event type

### copyFor

public Event copyFor(Object newSource, EventTarget newTarget)
Creates and returns a copy of this event with the specified event source and target. If the source or target is set to `null`, it is replaced by the `NULL_SOURCE_TARGET` value.

Parameters:
  `newSource` - the new source of the copied event
  `newTarget` - the new target of the copied event
Returns:
  the event copy with the new source and target

### isConsumed

public boolean isConsumed()
Indicates whether this `Event` has been consumed by any filter or handler.

Returns:
  `true` if this `Event` has been consumed, `false` otherwise

### consume

public void consume()
Marks this `Event` as consumed. This stops its further propagation.

### clone

public Object clone()
Creates and returns a copy of this `Event`.

Overrides:
  `clone` in class `Object`
Returns:
  a new instance of `Event` with all values copied from this `Event`.

### fireEvent

public static void fireEvent(EventTarget eventTarget, Event event)
Fires the specified event. The given event target specifies the path through which the event will travel.

Parameters:
  `eventTarget` - the target for the event
  `event` - the event to fire
Throws:
  `NullPointerException` - if eventTarget or event is null