Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,579 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.