0

I'm making an Oregan Trail game and am trying to simulate a driving like experience.

enter image description here

Basically, when I click 'travel' I want the jpanel in the top right to display "traveling" as shown in the picture. And then a few seconds later I want the top right JPanel to remove "traveling" and display different information.

Using Thread.sleep froze my application. I've also tried using SwingWorker and it somewhat worked. The JPanel that says traveling would disappear and the new one would appear, but I had to click a button first instead of it automatically appearing.

How can I have the JPanel/application wait a set amount of time and then automatically display the new information?

A--C
  • 36,351
  • 10
  • 106
  • 92
  • While not directly related to your question, you might want to check out [JAce](http://sourceforge.net/projects/java-ace/). – Elliott Frisch Nov 29 '13 at 00:55
  • You should use [javax.swing.Timer](http://docs.oracle.com/javase/7/docs/api/javax/swing/Timer.html). Also see this [Answered Question](http://stackoverflow.com/questions/7816585/program-freezes-during-thread-sleep-and-with-timer) – Paul Samsotha Nov 29 '13 at 02:18
  • Thank you all for the answers. I ended up going with the Timer, it made the most sense to me and I got it working. Thanks – user3011646 Nov 29 '13 at 03:55

2 Answers2

1

I would probably use a Future<T>.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
0

I'm not much of an UI guy, but I know that in out GUI client application we use Foxtrot to manage UI stuff.

kovica
  • 2,443
  • 3
  • 21
  • 25