简体   繁体   English

JavaFX时间线监听器

[英]JavaFX timeline listeners

Problem description: 问题描述:

I have an timeline that is shared between two classes and is binded with an slider. 我有一个在两个类之间共享的时间轴,并与滑块绑定在一起。 In each class I have a listener to the timeline that does something. 在每个课程中,我都有一个监听时间轴的东西,该时间轴可以执行某些操作。

In one listener I manipulate an array with some objects at some point of time + some changes to the slider may appear => changes to timeline. 在一个侦听器中,我在某个时间点使用一些对象操纵一个数组+可能会出现对滑块的某些更改=>时间轴的更改。

In the other listener I get the current time and do some stuff with it. 在另一个侦听器中,我得到了当前时间并对其进行了一些处理。 But now I'm trying to add functionality to this listener and check when my time from slider (maxValue) will reach end and through binding also the "end" time of the timeline. 但是,现在我正尝试向此侦听器添加功能,并检查滑块(maxValue)上的时间何时到达终点,并且还通过绑定时间轴的“终点”时间。 When this is happening I want to redraw the slider and change the timeline to fit the new slider changes. 发生这种情况时,我想重新绘制滑块并更改时间线以适应新的滑块更改。

As an example: 举个例子:

I have an slider from 0 to 10 min and a timeline that is binded. 我有一个从0到10分钟的滑块和一个绑定的时间轴。 So, I want when the timeline/slider reaches 10 min then to redraw the slider+ adjust the timeline to have something like: 0 to 20 min and the current time to be at 10 min. 所以,我想当时间轴/滑块达到10分钟时,然后重绘滑块+调整时间轴,使其具有如下内容:0到20分钟,当前时间为10分钟。

LE: I tried to do something and I get this error (maybe helps) LE:我尝试做某事,但出现此错误(也许有帮助)

java.lang.NullPointerException
at com.sun.scenario.animation.shared.SimpleClipInterpolator.interpolate(SimpleClipInterpolator.java:132)
at com.sun.scenario.animation.shared.TimelineClipCore.playTo(TimelineClipCore.java:188)
at javafx.animation.Timeline.impl_playTo(Timeline.java:182)
at com.sun.scenario.animation.shared.InfiniteClipEnvelope.timePulse(InfiniteClipEnvelope.java:131)
at javafx.animation.Animation.impl_timePulse(Animation.java:953)
at com.sun.scenario.animation.shared.AnimationPulseReceiver$1.run(AnimationPulseReceiver.java:133)
at com.sun.scenario.animation.shared.AnimationPulseReceiver$1.run(AnimationPulseReceiver.java:131)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.scenario.animation.shared.AnimationPulseReceiver.timePulse(AnimationPulseReceiver.java:131)
at com.sun.scenario.animation.AbstractMasterTimer.timePulseImpl(AbstractMasterTimer.java:365)
at com.sun.scenario.animation.AbstractMasterTimer$MainLoop.run(AbstractMasterTimer.java:288)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:459)
at com.sun.javafx.tk.quantum.QuantumToolkit$9.run(QuantumToolkit.java:332)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67)
at java.lang.Thread.run(Thread.java:744)

Thanks in advance! 提前致谢!

Ok now works! 现在可以了! What was the problem: the problem was that I tried to manipulate the keyFrames from a changelistener of the timeline's currentProperty() in place. 问题出在哪里:问题是我试图从时间轴的currentProperty()的变更侦听器中操纵keyFrame。

The solution to my problem was actually to create another changelistener for the slider.maxProperty() where I added the keyFrames that I wanted. 解决我的问题的方法实际上是为slider.maxProperty()创建另一个changelistener,在其中添加了想要的keyFrames。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM