tbee at tbee.org
Tue Mar 6 04:44:25 PST 2012
Trying to wrap this in a generic class, but I keep running into snags. Your approach always had an initial delay, because even if the timeline's delay is set to 0, the timer still will delay the KeyFrame's duration.
I've attempted to use two keyframes.
- the first at delay (can be 0)
the first has the onFinished handler
- the second at delay + cycle time
the second will reset the timeline to the first
This works only if I reset the timeline to first - 1ms.
On 6-3-2012 13:25, Michael Heinrichs wrote:
> Yes, all classes that inherit from Animation have a delay property (a Duration). The delay will only be considered at the very start of an animation and not during looping. Use only one KeyFrame for the loop duration. So for example if you have a delay of 500ms and a KeyFrame at 100ms, you will get notifications like this:
> 600ms 700ms 800ms...
> - Michael
> On 06.03.2012, at 13:05, Tom Eugelink wrote:
>> I have been pondering this as well, but would this do the initial delay and the quick repeat afterwards? Or should I use the first KeyFrame for the initial delay and a second KeyFrame for the repeat delay (which just jumps the timeline back to the first). I could wrap this into a real timer class then.
>> On 6-3-2012 11:56, Michael Heinrichs wrote:
>>> Hi Tom,
>>> I think you can either use a standard Timer or a Timeline with a single KeyFrame and cycleCount INDEFINITE. Your logic needs to go into the onFinished handler. There is a property in Timeline to set an initial delay.
>>> - Michael
>>> On 06.03.2012, at 11:44, Tom Eugelink wrote:
>>>> For the second time I'm in need of a timer logic, similar to Swing's timer class.
>>>> What I want to do is that when there is a mouse-pressed event, a timer is started with an initial delay of 500 ms or s,o and then it must repeat every 100 or 200 ms and increment a value. Real world: the user presses-and-holds the LMB over an arrow in the spinner control, and it must start incrementing; tak tak tak tak tak, maybe picking up speed or step size as the button is held.
>>>> There is AFAIK no timer class in JavaFX. There is an AnimationTimer, but that is closely linked to the repaint frequency, this usage should not be.
>>>> The other time I needed a timer, all I needed was a single delayed execution, so I abused the PauseTransition and the onFinished event. But now I need the repeating behavior and Animations do not have an onTrigger or something.
>>>> What is the best way to do a Swing like timer in JavaFX?
More information about the openjfx-dev