aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JLabel.setText() is NOT Updating the Text Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JLabel.setText() is NOT Updating the Text" Watch "JLabel.setText() is NOT Updating the Text" New topic
Author

JLabel.setText() is NOT Updating the Text

AmritP Singh
Greenhorn

Joined: May 10, 2012
Posts: 20
Hi Everyone,

i am developing a new Hangman game for school assignment. The game is working fine for the first time. If user clicks on the Button Try Again , to try one more time, computer randomly picks up another String.When i try to update the JLabel with the New String. Its not Happening.

There is a string in my code

"private String populateDashes = "";"

populateDashes String is used to print Dashes in JPanel something like in this (-----). This is based on the String length. This works fine for first time, however when the User try to play agai, the Label is not getting updated with the new String. Can some help me out with this.

i am posting my Complete Code here.




Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2366
    
  50
This works fine for first time, however when the User try to play agai, the Label is not getting updated with the new String. Can some help me out with this.

You are not restarting the game you are creating a new Hangman3 object but you aren't displaying it (or closing the original one) so what you can see is the original Hangman3 GUI.
BTW this is not the way to handle a play again request. You need to separate your GUI initialisation code (creation of GUI components) from your game code (populating of values) so you can restart the existing Hangman3 game by selecting a new word and calling the game code again.
AmritP Singh
Greenhorn

Joined: May 10, 2012
Posts: 20
Thanks. I have to change a lot of things to make it work.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JLabel.setText() is NOT Updating the Text