• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Simple slot machine

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:


 
Ranch Hand
Posts: 123
Firefox Browser Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Bartender
Posts: 1464
32
Netbeans IDE C++ Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Ranch Hand
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
use a Swing Timer
 
reply
    Bookmark Topic Watch Topic
  • New Topic