• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JLabel.setText() is NOT Updating the Text

 
AmritP Singh
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2953
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I have to change a lot of things to make it work.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic