-3

I know there are some questions about this topic but none of these helped me to find a solution. I've got two Timeline Animations, I want to execute them after a delay of a few seconds. I'm gonna show you an example:

Every time I click my mouse, the Animation shall reset to its default delay time, let's say 5 seconds. If I'll do nothing the time's running away until it's zero. And when I reach the 0 seconds, the Animation has to start(). And so on.

Of course Thread.sleep() would make my UI freeze until the mission is done. And I don't know whether I should use Thread, Task or other classes because the work is not that complex.

There are a bunch of ways to do it, but I'm not experienced in multithreading and I wanna learn to make it efficiently. Thank you guys a lot.

Rouman
  • 127
  • 2
  • 14
  • 2
    You don't need any threading: the animation API already has everything you need to do the kinds of things you are describing. Your description isn't very clear though. Can you [edit] the post and show some of the code you have so far, and explain more clearly what you want to happen. (As I understand it, the animation runs repeatedly if the user doesn't do anything, but if the user clicks the mouse, it pauses for some time and then restarts from the beginning?) – James_D Sep 06 '16 at 19:34
  • Exactly. I think my code is unnecessary in this case. I just need the way to do it or a few method names. – Rouman Sep 06 '16 at 19:41
  • 2
    It's much easier to answer a question by showing some code. No-one really wants to write code from scratch to solve *your* problem, so it's much easier to answer if you provide a complete, executable example that does the parts you do understand. Don't make it harder to help you than it needs to be. – James_D Sep 06 '16 at 19:43
  • 1
    Excuse me? I can answer this pretty easily: however in my experience, if I provide an answer to something that is this badly stated, all that's going to happen is that you're going to reply with "No, that's not what I meant", so it ends up wasting both of our time. Do you want help (for free), or not? If so, make it easy for people to help you. If not, don't ask in the first place. – James_D Sep 06 '16 at 19:53
  • OK, if you want, I will provide an answer along those lines. – James_D Sep 06 '16 at 20:02

1 Answers1

2

You can probably achieve what you want using

timeline.setDelay(...);

to specify a delay before the timeline starts,

timeline.setCycleCount(Animation.INDEFINITE);

to make it repeat indefinitely, and

timeline.playFromStart();

to make it start again from the beginning (after its specified delay).

James_D
  • 201,275
  • 16
  • 291
  • 322
  • 3
    @Rouman In general, you should accept answers if they answer your question (you have not accepted any answers to date). Doing so will help other users find an answer if they have similar questions. In this case, it's probably a moot point as I don't really believe your question is clear enough to help others (your opinion will likely vary), but some of your other questions have answers that should be accepted. – James_D Sep 06 '16 at 20:33
  • The problem is that none of the previous answers helped me that much. They gave me ideas but they didn't solve my problem at all. I appreciate your answer from above but this one didn't help me neither. That's why I am not interested in helping the community, I just don't care, this is a shi*ty board and I'm going to find a better one. Seems like there are so many "experts" on this platform who are not able to give some good tips even if the question contains everything what's needed. – Rouman Sep 07 '16 at 14:37
  • @Rouman Your previous comment is not consistent with your response to the answer to [this question](http://stackoverflow.com/questions/38819690/javafx-media-pause-method-makes-mediaplayer-fast-forward), for example.I argued that my answer probably wouldn't help, and that without a more carefully-specified question, it would be hard to provide a useful answer. Maybe if you are consistently not getting the answers you want, you should think more carefully about whether your questions are conducive to useful answers. That advice is supposed to help you get the help you are seeking. – James_D Sep 07 '16 at 14:41