Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Build a JavaFX Application It's About Time Timeline Animation

Siu KWAN Yuen
PLUS
Siu KWAN Yuen
Courses Plus Student 2,898 Points

setCycleCount() getKeyFrames()

Craig used both of the methods to update the field of Timeline instance. However, when Craig set the cycleCount, he used a set method, while Craig set the keyFrame, he updates the field by getting the reference of the KeyFrames and passing the new value into the reference.

From my observation in this course, adding value to fields by getting the reference and updating the reference is rare in Java, but since the Java FX course begin, this approach became very common.

Is there a guideline for adopting the correct approach? (for example, can I set the cycleCount by getCycleCount.add(.....) ? )

Caleb Kleveter
Caleb Kleveter
Treehouse Moderator 37,862 Points

That is a very good question Siu. I am not very fluent in Java, and I am not familiar with the language guidelines, so I am not sure what the answer is. I hope you find your answer!

1 Answer

Siu KWAN Yuen
PLUS
Siu KWAN Yuen
Courses Plus Student 2,898 Points
private Timeline timeline 
timeline.setCycleCount(kind.getTotalSeconds) 
// "kind.getTotalSecond" is a method defined by Craig and just consider it as an int. 

timeline.getKeyFrames(new KeyFrame(Duration.second(1), ........)