javafx官方文档学习之Event体系理解

我的博文小站:http://www.xby1993.net 最新资讯都在那里。

主要讲javafx.event package:

141920_zwIi_568007.jpg

javafx.event

Interface EventTarget

EventDispatchChainbuildEventDispatchChain(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.

EventDispatchChainappend(EventDispatcher eventDispatcher)

Appends the specified EventDispatcher to this chain.

EventdispatchEvent(Event event)

Dispatches the specified event through this EventDispatchChain.

EventDispatchChainprepend(EventDispatcher eventDispatcher)

Prepends the specified EventDispatcher to this chain.

继续转向EventDispatcher:事件分派者对象:

javafx.event

Interface EventDispatcher

EventdispatchEvent(Event event, EventDispatchChain tail)

Dispatches the specified event by this EventDispatcher.

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.Objectclone()

Creates and returns a copy of this Event.

voidconsume()

Marks this Event as consumed.

EventcopyFor(java.lang.Object newSource, EventTarget newTarget)

Creates and returns a copy of this event with the specified event source and target.

static voidfireEvent(EventTarget eventTarget, Event event)

Fires the specified event.

EventType<? extends Event>getEventType()

Gets the event type of this event.

EventTargetgetTarget()

Returns the event target of this event.

booleanisConsumed()

Indicates whether this Event has been consumed by any filter or handler.

继续转向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.StringgetName()

Gets the name of this event type.

EventType<? super T>getSuperType()

Gets the super type of this event type.

java.lang.StringtoString()

Returns a string representation of this EventType object.


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 a Button has been fired, when a KeyFrame(补间动画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该事件。

转载于:https://my.oschina.net/xby1993/blog/184352

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值