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 Wire It Up

Alan Kennedy
PLUS
Alan Kennedy
Courses Plus Student 616 Points

Why was it used?

public void handlePlay(ActionEvent actionEvent) { if(mCurrentAttempt==null){ handleRestart(actionEvent); } else { playTimer(); } }

Jenna Dercole
Jenna Dercole
30,224 Points

We need some context before we can give you a proper answer. What lesson does this pertain to? Why is what used?

1 Answer

Matthew Timmons
Matthew Timmons
33,804 Points

When the application is first started, mCurrentAttempt is null. It is only set in the method, "prepareAttempt," which is only called in the method, "handleRestart." This logic says, "Check if mCurrentAttempt is null. If it is, then go ahead and call the function, 'handleRestart.' This will instantiate the variable, mCurrentAttempt. It will then start the timer. If it is not null, A.K.A. it has been instantiated at some point in this application, then just call the method, 'playTimer.'"

The flow can be represented as:

App starts -> User clicks the play button -> handlePlay sees that mCurrentAttempt is null, so it calls the same method that the restart button calls, "handleRestart" -> App calls prepareAttempt(AttemptKind.FOCUS), which sets the timer to 25 minutes and sets the styles -> app calls playTimer() which starts the timer.

Please let me know if this helps or if you have any questions. Thank you.