title: Hangman: Remember Previous Guesses
body: <p>I am quite new Java so this might sound silly. <br/> <br/>
  I am trying to create a GUI based Hangman Game from Java. I've created list of buttons from array and it returns the individual letter as character when clicked. I have got list of Words to guess and every time a button is pressed it needs to compare the word with the pressed letter and replace if it matches.</p>
  
  <p>A friend of mine suggested using an array to split and check letters but I'm not familiar with those stuffs. As I need to keep track of wrong input as well as count errors, I am not sure if it is the best idea to use the StringBuilder. If StringBuilder is the best option for me please help me with the problem below:</p>
  
  <pre><code> String word = retWord; // The actual word  
   String s = "" + guessed; //Changing guessed letter to string 
   StringBuilder gletters = new StringBuilder(s);  
   String mainword = word.replaceAll("[^" + gletters + "]", "_"); //Replacing the matching letters  
   a.setText(mainword);
  </code></pre>
  
  <p>The code is performed inside <code>FOR</code> loop of button press, but the output needs to be 'apple'. Every time at button press the output looks something like this:</p>
  
  <p><b>When A is pressed :</b>A _ _ _ _<br>
  <b>When P is pressed :</b>_ p p _ _<br>
  <b>When L is pressed :</b>_ _ _ L _<br>
  <b>When E is pressed :</b>_ _ _ _ E  </p>
  
  <p><strong>My question is</strong> how am I supposed to make it remember previous guesses that were correct, not just the current one?
  Also how can I count errors for wrong button presses?</p>
  
  <p>Any help would be appreciated.</p>