• Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple Java GUI help

 
George Vince
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey there, I'm just starting to learn Java GUI. I'm trying to make a simple GUI that will update dynamically but having trouble ending the loop correctly. Can anyone see what I'm doing wrong? Thanks for help!
Currently I've got the GUI updating and stopping, but the Test class method loop does not terminate correctly, it continues to count.

Thanks!

GUI CLASS



Test Counter Class


 
Campbell Ritchie
Marshal
Posts: 52516
118
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use Thread.sleep in Swing; since Swing (like all GUI frameworks) is not thread safe, everything has to run on the one thread. If you sleep that thread you can make the entire GUI unresponsive. You can read more about threads here.
Why have you got a static field in the Test class? If you don't have a good reason for it, using the keyword static is a mistake.

Don't use null Layout. Always use a concrete layout, as in the Java Tutorials, MigLayout, etc.

I shall move this discussion to our GUIs forum.
 
Campbell Ritchie
Marshal
Posts: 52516
118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Darryl Burke
Bartender
Posts: 5152
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, Swing has its own Timer (javax.swing.Timer) which is better suited to interactions with Swing GUIs than the one you have used (java.util.Timer).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!