Ajay Vaghela
Ajay Vaghela

Reputation: 41

JavaFX8 Timeline playing issue

I am using multiple Timelines in my application as

Timeline timeLine1 = new Timeline(new KeyFrame(Duration.seconds(1), actionEvent -> {
        System.out.println("Enter in timer for check and playcontent");
        MaintainPlaybackArray.checkAndPlayContent();
    }));
    timeLine1.setCycleCount(Timeline.INDEFINITE);
    timeLine1.play();

Which will play each seconds

Timeline timeLine2 = new Timeline(new KeyFrame(Duration.seconds(5), actionEvent -> {
        System.out.println("Enter in timer");
        getSchedule();
        checkSchedule();
    }));
    System.out.println("after timer");
    timeLine2.setCycleCount(Timeline.INDEFINITE);
    timeLine2.play();

Which Calls every 5 Seconds

Timeline timeLine3 = new Timeline(new KeyFrame(Duration.seconds(10), actionEvent -> {
        System.out.println("in timer");
        String currentChecksum = Util.md5(getScheduleJsonArray().toJSONString());
        if (currentChecksum != null && !currentChecksum.equalsIgnoreCase(checksum)) {
            System.out.println("Schedule changed");
            isScheduleChanged = true;
            checksum = currentChecksum;
        }
    }));
    System.out.println("after timer");
    timeLine3.setCycleCount(Timeline.INDEFINITE);
    timeLine3.play();

which will executes after each 10 second.

Problem

When i execute the application after starting all the timelines it cannot play in synchronous manner.

i.e: timLine1 will not executes for 8 seconds and then suddenly it executes 8 times at a time. timeline2 will execute any time like after 8 seconds or twice after 12 seconds. timeLine3 will executes after 12 seconds or 15 seconds.

So, Please help so that i can execute the code in synchronous manner. is there anything i can use instead of Timeline?

Upvotes: 2

Views: 107

Answers (1)

Uluk Biy
Uluk Biy

Reputation: 49215

Use ParallelTransition or SequentialTransition depending on your needs.

Upvotes: 0

Related Questions