title: Updating JLabel text output for counter not working
body: <p>So I am creating a number guessing game. The computer generates a random number, the user inputs a guess, then the computer lets the user know if they've won, or if the guess was less than or more than the random number. This goes on until they've got it right, or press play again (which resets it).</p>
  <p>I want to count and display the number of guesses a user makes each round. So I am incrementing 'tallyValue' for each guess. I know it is counting and incrementing the values correctly. However for instance if the user guesses twice in a row values that are less than the random number, then the tally value doesn't update on the .setText output. It will only update when the users guesses alternate from less than the random number to more than the random number.</p>
  <p>What am I missing? I've tried removing and then setting the text but I don't understand why this happens.</p>
  <pre><code>MyFrame() {
          this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //exit out of app 
          this.setLayout(new FlowLayout());
  
          //add labels, buttons and input fields
          button = new JButton(&quot;Submit&quot;);
          button.addActionListener(this); //can just pass in this because we already pass actionlistener above
  
          JLabel instruction = new JLabel();
          instruction.setText(&quot;Input Your Guess (must be between 1 and 100&quot;);
  
          textField = new JTextField();
          textField.setPreferredSize(new Dimension(250,40));
  
          tally = new JLabel();
          tally.setText(&quot;Number of guesses: &quot; + tallyValue);
  
          outputMessage = new JLabel();
          outputMessage.setText(&quot;Take a guess!&quot;);
  
          playAgainButton = new JButton(&quot;Play Again&quot;);
          playAgainButton.addActionListener(this);
  
          this.add(instruction);
          this.add(textField);
          this.add(button);
          this.add(playAgainButton);
          this.add(outputMessage);
          this.add(tally);
          this.setTitle(&quot;Number Guessing Game&quot;);
          this.setVisible(true); //make frame visible
          this.pack(); //frame size adjusts to components
  
          ImageIcon icon = new ImageIcon(&quot;res/game-icon.png&quot;); //creates an image icon
          this.setIconImage(icon.getImage());//changes icon of frame
  
          System.out.println(randomNumber); //for testing purposes
      }
  
      //add any unimplemented methods because we are using an interface
      @Override
      public void actionPerformed(ActionEvent e) {
          if(e.getSource()==button) {
              int textFieldValue;
  
              this.remove(outputMessage);
              try {
                  textFieldValue = Integer.parseInt(textField.getText());
                  //if guess is correct
                  if(textFieldValue == randomNumber) {
                      outputMessage.setText(&quot;Congratulations you guessed correctly!&quot;);
                      this.add(outputMessage);
  
                      tallyValue++;
                      
                      displayCount(tallyValue);
  
                      this.pack();
                      textFieldValue = 0; //reset text field val
                      
                      
                  }
                  //if guess is less than randomNumber
                  if(textFieldValue &lt; randomNumber) {
                      outputMessage.setText(&quot;Incorrect - the number I am thinking of is more than that&quot;);
                      this.add(outputMessage);
  
                      tallyValue++;
                      
                      displayCount(tallyValue);
                      
                      this.pack();
                      textFieldValue = 0; //reset text field val
                      
                  }
                  //if guess is more than randomNumber
                  if(textFieldValue &gt; randomNumber) {
                      outputMessage.setText(&quot;Incorrect - the number I am thinking of is less than that&quot;);
                      this.add(outputMessage);
  
                      tallyValue++;
                      System.out.println(tallyValue);
                      displayCount(tallyValue);
  
                      this.pack();
                      textFieldValue = 0; //reset text field val
                      
                  }
               }
              catch (NumberFormatException ex){
                  outputMessage.setText(&quot;You must insert a valid number&quot;);
                  this.add(outputMessage);
                  this.pack();
              }
          }
  
          if(e.getSource()==playAgainButton) {
              System.out.println(&quot;pa&quot;);
              this.remove(outputMessage);
              randomNumber = rand.nextInt(101);
              outputMessage.setText(&quot;Take a guess!&quot;);
              this.add(outputMessage);
  
              
              tallyValue = 0;
              displayCount(tallyValue);
              
              this.pack();
          }
      }
  
      private void displayCount (int tv) {
          this.remove(tally);
          tally.setText(&quot;Number of guesses:&quot; + tv);
          this.add(tally);
          this.pack();
      }
  </code></pre>