File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple slot machine

 
Christoffer Killander
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 123
Firefox Browser Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Pie
Posts: 985
10
C++ Java Netbeans IDE Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use a Swing Timer
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic