#Unexpected behavior with TimeUnit.seconds.sleep(x)

8 messages · Page 1 of 1 (latest)

devout frost
#
startAndEndRoundButton.setText(testString);
        try
        {
            TimeUnit.SECONDS.sleep(5); // how long each number stays up to be memorized;
        }
        catch (InterruptedException e)
        {

        }
startAndEndRoundButton.setText("Click to submit guess");

I would expect testString to display for 5 seconds and then "Click to submit guess" to display. Instead it pauses for 5 seconds and then displays "Click to submit guess"

What is the mechanism that is causing this and can I do anything to fix it?

Tagged as multithreading because it seems that sleep is used a fair bit in threading things, even though this is a simple single thread program.

gleaming kilnBOT
#

This post has been reserved for your question.

Hey @devout frost! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

agile moss
#

What is the type of startAndEndRoundButton?

Intuitively, it feels to me like there's some "render" call happening after your code snippet that is making the "Click to submit guess" text actually display.

#

@devout frost

devout frost
agile moss
#

Ah, I've never used JavaFX before. So if this is something specific to that library, someone else will have to chime in. But yeah lmk if you find anything that could be "showing" this button after your code snippet, because if the showing is happening afterwards then the initial setText is moot.

devout frost
#

yep, that's it. Anyone searching this in the future- I'd recommend using pausetransition and having the event you want to trigger occur at the end of it.