Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes Simple slot machine Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Simple slot machine" Watch "Simple slot machine" New topic
Author

Simple slot machine

Christoffer Killander
Greenhorn

Joined: Jul 06, 2011
Posts: 5
Hello. I am current working on a simple slot machine.
the problem that i have is creating a delay between the reels when they "spin".
i have tried using a Thread.sleep() but it does not update the textarea until all the reels have spun.

all help is appreciated
// Christoffer K

The Code:


Kathleen Angeles
Ranch Hand

Joined: Aug 06, 2012
Posts: 122

Look into the page below:
http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html

Threads and concurrency are something that you need to learn when your gui has some dynamism like yours.

The main thread could be busy doing the calculations and other non-gui stuff. the gui is choked and not given its own time to update itself. in short, the trick is to use 1 or more additional threads. e.g. let the main thread handle non-gui stuff. make threads that would do gui stuff, like update your slot machine..
Stevens Miller
Ranch Hand

Joined: Jul 26, 2012
Posts: 523
    
    3

Kathleen Angeles wrote:Look into the page below:
http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html

Threads and concurrency are something that you need to learn when your gui has some dynamism like yours.

The main thread could be busy doing the calculations and other non-gui stuff. the gui is choked and not given its own time to update itself. in short, the trick is to use 1 or more additional threads. e.g. let the main thread handle non-gui stuff. make threads that would do gui stuff, like update your slot machine..

Keeping in mind, of course, that Swing is not thread-safe, which means you want your GUI activity to take place entirely on the "event dispatching thread," (which some people might think of as the thread you are calling "the main thread," in which case, having other threads do GUI stuff would cause problems).
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
use a Swing Timer
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simple slot machine