我的博文小站:http://www.xby1993.net 最新资讯都在那里。
主要讲javafx.event package:
javafx.event
Interface EventTarget
而
EventDispatchChain | buildEventDispatchChain(EventDispatchChain tail) Construct an event dispatch chain for this target. |
再转向EventDispatchChain事件分派链对象:
他就是一个事件分派者链。
Represents a chain of EventDispatcher
objects, which can dispatch an Event
. The event is dispatched by passing it from one EventDispatcher
to the next in the chain until the end of chain is reached. Each EventDispatcher
in the chain can influence the event path and the event itself. The chain is usually formed by following some parent - child hierarchy from the root to the event target and appending all EventDispatcher
objects encountered to the chain.
EventDispatchChain | append(EventDispatcher eventDispatcher) Appends the specified |
Event | dispatchEvent(Event event) Dispatches the specified event through this |
EventDispatchChain | prepend(EventDispatcher eventDispatcher) Prepends the specified |
继续转向EventDispatcher:事件分派者对象:
javafx.event
Interface EventDispatcher
Event | dispatchEvent(Event event, EventDispatchChain tail) Dispatches the specified event by this |
An EventDispatcher
represents an event dispatching and processing entity. It is used when an Event
needs to be dispatched to the associated EventTarget
through the EventDispatchChain
specified by the target. Each EventDispatcher
in the chain can influence the event path and the event itself. One EventDispatcher
can appear in multiple chains.
The system defines two successive phases of event delivery. The first phase is called capturing phase and happens when when an event travels from the first element of the EventDispatchChain
associated with the event target to its last element. If the event target is part of some hierarchy, the direction of the event in this phase usually corresponds with the direction from the root element of the hierarchy to the target. The second phase is called bubbling phase and happens in the reverse order to the first phase. So the event is returning back from the last element of the EventDispatchChain
to its first element in this phase. Usually that corresponds to the direction from the event target back to the root in the event target's hierarchy.
事件的传送分为两个阶段,第一阶段由事件树root至下传送,第二阶段正好相反,有leaf至root传送。
Each EventDispatcher
in an EventDispatchChain
is responsible for forwarding the event to the rest of the chain during event dispatching. This forwarding happens in the dispatchEvent
method and forms a chain of nested calls which allows one EventDispatcher
to see the event during both dispatching phases in a single dispatchEvent
call.
Template for dispatchEvent
implementation.
public Event dispatchEvent(Event event, EventDispatchChain tail) {
// capturing phase, can handle / modify / substitute / divert the event
if (notHandledYet) {
// forward the event to the rest of the chain
event = tail.dispatchEvent(event);
if (event != null) {
// bubbling phase, can handle / modify / substitute / divert
// the event
}
}
return notHandledYet ? event : null;
}
继续转向Event事件对象:
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.
java.lang.Object | clone() Creates and returns a copy of this |
void | consume() Marks this |
Event | copyFor(java.lang.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 |
继续转向EventType:
javafx.event
Class EventType<T extends Event>
This class represents a specific event type associated with an Event
.
Event types form a hierarchy with the EventType.ROOT
(equals to Event.ANY
) as its root. This is useful in event filter / handler registration where a single event filter / handler can be registered to a super event type and will be receiving its sub type events as well.
事件类型组织成父子层次关系以便于事件类型的过滤与处理。
Field:
static EventType<Event> | ROOT The root event type. |
Method:
java.lang.String | getName() Gets the name of this event type. |
EventType<? super T> | getSuperType() Gets the super type of this event type. |
java.lang.String | toString() Returns a string representation of this |
ActionEvent:
javafx.event
Class ActionEvent
java.lang.Object
java.util.EventObject
public class ActionEventextends Event
An
Event
representing some type of action. This event type is widely used to represent a variety of things, such as when aButton
has been fired, when aKeyFrame(补间动画Timeline的关键帧)
has finished, and other such usages.Direct Known Subclasses:
MediaMarkerEvent
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Field:
static EventType<ActionEvent> | ACTION The only valid EventType for the ActionEvent. |
继续MediaMarkerEvent虽然他是javafx.media包下的,但是由于它是ActionEvent的直接子类。继续研究。
public class MediaMarkerEventextends ActionEvent
An ActionEvent
representing a media marker. A marker is added to a Media
which is then played by a MediaPlayer
. The event is fired when the playback position reaches the position of the marker.
See Also:
MediaPlayer.onMarker
看到这里明白了,就是音乐流Media设置标志mark后一旦播放到标志,就会触发MediaMarkerEvent该事件。