title: Coding for the first time (Java hangman game)- going from console-based to GUI
body: <p>I am <strong>completely new to programming</strong> and I have to complete some tasks in Java (I'm using Eclipse). This one is a <strong>hangman game</strong>. My code is below. I have written a console-based program that basically works (counting lives instead of drawing a hangman graphic). </p>
  
  <p>I think this question will seem very simple to most people, but I would really appreciate your help. </p>
  
  <p>I am trying my best to look for answers online, but as a complete novice it is hard to know where to start. I would really just like to know if I am on the right track so that I don't waste too much time. </p>
  
  <p><strong>I am supposed to (and want to!) do this myself, so ideally I would like hints on what to focus on.</strong></p>
  
  <p>The questions I have are:</p>
  
  <ol>
  <li>I now need to <strong>create a GUI</strong> (which I have never done before):
  <em>how useful is this code that I have already worked out? Is everything completely different once I start creating the game with a GUI?</em></li>
  <li>I used a <code>StringBuffer</code> to store the previously guessed letters. I
  wanted to <strong>search</strong> this in order to display the word with all the
  previously guessed letters filled in (as it stands it only prints
  out the current guess with all the other letters obscured). Is that
  possible?</li>
  </ol>
  
  <hr>
  
  <pre><code>public static void main(String[] args) {
      Scanner myScanner = new Scanner(System.in);
      StringBuffer buffer = new StringBuffer();
  
      String secretWord;
      int secretWordLength;
      int position;
      int livesLost = 0;
      int totalLives = 10;
      int lettersRemaining;
      boolean guessInWord;
      char guess;
      StringBuffer prevGuessedLetters;
  
      //prompt user to enter a word and set as an instance of the secretWord variable
      System.out.println("Enter a word:");
      secretWord = myScanner.next();
  
      //determine the length of the word entered
      secretWordLength = secretWord.length();
      System.out.println(secretWordLength);
      lettersRemaining = secretWordLength;
  
      for (position = 0; position &lt; secretWordLength; position++) {
          System.out.print("*");
      }
      System.out.println();
  
      //loop starts
      while (lettersRemaining &gt; 0 &amp;&amp; livesLost &lt; 10) {
          //prompt user to guess a letter
          System.out.println("Guess a letter:");
          guess = myScanner.findWithinHorizon(".", 0).charAt(0);
  
          //check if the letter guessed is in the secretWord  
          guessInWord = (secretWord.indexOf(guess)) != -1;
  
          if (guessInWord == false) {
              livesLost++;
              System.out.print("Sorry, you have lost a life. You still have ");
              System.out.print(totalLives -= livesLost);
              System.out.println(" life/lives left. Keep trying.");
          } else {
              System.out.println("That was a good guess, well done!");
  
              for (position = 0; position &lt; secretWordLength; position++) {
                  if (secretWord.charAt(position) == guess) {
                      System.out.print(guess);
                      lettersRemaining--;
                  } else {
                      System.out.print("*");
                  }
              }
          }
          System.out.println();
          prevGuessedLetters = buffer.append(guess);
          System.out.print("Previously guessed letters: ");
          System.out.println(prevGuessedLetters);
          System.out.print("Letters remaining: ");
          System.out.println(lettersRemaining);
      }
  
      if (livesLost == totalLives) {
          System.out.println("Sorry, you lose!");
      } else {
          System.out.print("Well done, you win! The word was ");
          System.out.println(secretWord);
      }
  }
  </code></pre>