title: How can I get this hangman program into a GUI?
body: <p>First, I figured I would try to write a standard hangman program without the GUI.  I was able to succeed doing that.  But I'm having trouble getting it into the GUI.  I seem to struggle with GUIs the most.</p>
  
  <p>I'll show my code so far.  Maybe you guys could point me in the right direction? Or tell me if I'm on the right track?</p>
  
  <p>Driver:</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  
  public class Hangman {
      public static void main (String[] args){
          JFrame frame = new JFrame ("Hangman");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
          HangmanPanel hmp = new HangmanPanel();
  
          frame.getContentPane().add(hmp);
          frame.pack();
          frame.setVisible(true);
  
      }
  
  
  }
  </code></pre>
  
  <p>Panel Class  (this one is a bit messy, because I'm trying to experiment, and I'm going through a trial and error process I guess)  My apologies if its logically off.</p>
  
  <pre><code>import java.awt.Panel;
  import java.util.Scanner;
  import java.util.Random;
  import javax.swing.BorderFactory;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  
  public class HangmanPanel extends JPanel {
  
  private Hangman hm;
      Scanner input = new Scanner(System.in);
      final String[] WordList = { "ADA", "COBOL", "LOGO", "BASIC", "PROLOG",
              "UBUNTU", "UHURU" };
      String ChosenWord = WordList[(int) Math.random() * WordList.length];
      StringBuilder display = new StringBuilder(ChosenWord.length());{
  
  
  
  
      for (int i = 0; i &lt; ChosenWord.length(); i++)
          display.append("*");
  
      int NumberOfTries = 0;
  
      System.out.print("Let's Begin \n\n");
      System.out.println("Try to guess the word in 6 tries, or you're a dead man!\n\n");
  
      boolean correct = false;
  
      while (NumberOfTries &lt; 6 &amp;&amp; !correct) {
          String UserGuess = input.next();
          String Letter = UserGuess.substring(0, 1);
  
          if (ChosenWord.indexOf(Letter) &lt; 0) {
              System.out
                      .printf("The letter %s does not appear anywhere in the word.\n",
                              Letter);
              NumberOfTries++;
          }
  
          else {
              if (display.indexOf(Letter) &gt;= 0)
                  System.out
                          .printf("The letter %s has already been entered as a guess.\n",
                                  Letter);
  
              else {
                  for (int p = 0; p &lt; ChosenWord.length(); p++)
                      if (ChosenWord.charAt(p) == Letter.charAt(0))
                          display.setCharAt(p, Letter.charAt(0));
              }
          }
  
          correct = display.indexOf("*") &lt; 0;
          draw(NumberOfTries);
      }
  
      if (correct)
          System.out
                  .println("You have guessed "
                          + ChosenWord
                          + " correct and saved yourself from the gallos. Till next time that is.\n");
  
      else {
          System.out
                  .printf("You've had %d strikes against you. Thus you've been hung. Better luck next time.\n",
                          NumberOfTries);
      }
  }
  
  public static void draw(int num) {
      JPanel p1 = new JPanel();
      p1.setBorder(BorderFactory.createEtchedBorder());
      final String[] status = { "____\n|   |\n |   \n|\n|",
              "____\n| |\n| O\n|\n|\n|", "____\n| |\n| O\n|/|\n|\n|",
              "____\n| |\n| O\n|/|\\\n|\n|", "____\n| |\n| O\n|/|\\\n|/\n|",
              "____\n| |\n| O\n|/|\\\n|/\\\n|" };
      p1.add(new JLabel("Etched Border"));
  
      if (num &gt;= 0 &amp;&amp; num &lt; status.length) {
          System.out.println(status[num]);
      }
  
      else {
          System.out.println("Must be a Mistake. Out of Range.");
      }
  
  }
  </code></pre>
  
  <p>}</p>