It's not a secret anymore!*
The moose likes Swing / AWT / SWT and the fly likes delay in setVisible( true ) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "delay in setVisible( true )" Watch "delay in setVisible( true )" New topic
Author

delay in setVisible( true )

Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
I am trying to simulate dice rolling as follows:

You Rolled:

< 2 seconds pass >

You Rolled: 3

< 1 more second passes >

You Rolled: 3 + 4 = 7

Instead, the whole line displays at once after 3 seconds. Please tell me what is wrong.


Mike Gershman
SCJP 1.4, SCWCD in process
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

If you call rollDice() from an event handler, then the event thread -- which is also responsible for painting the screen -- is blocked as long as rollDice() runs. Nothing can change on the screen until the event thread becomes free.

For this reason, you should never do anything that takes longer than a few milliseconds on the event thread. If you need to start a long-running operation from the GUI, always do it by spawning a new thread -- i.e.,



[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: delay in setVisible( true )
 
Similar Threads
Help with this code
Need Help Understand this.
Can someone help me out with this code
Dice Game help and Arrays
Annoying Error