Maybe this will help. It's not exactly what you are looking to do, but its a hangman program I had to make for a CS course.
Code:
/*Matt Lewis
Hangman*/
import javax.swing.JOptionPane;
import java.util.Arrays;
public class Hangman
{
public static void main(String [] args)
{
String word = "phloem", let="s", dashii="------", whaddyawant, guess="";
int x=0, y=0, c=0;
char[] dashes = dashii.toCharArray();
char[] cheque = word.toCharArray();
System.out.println("HANGMAN!\n");
do{
whaddyawant=JOptionPane.showInputDialog("word or letter?");
if (whaddyawant.equalsIgnoreCase("word"))
{guess=JOptionPane.showInputDialog("Gues your word.");
if (guess.equalsIgnoreCase(word))
System.out.println("phloem\nYou got it!");}
else {
c=0;
x=0;
y++;
String inpt=JOptionPane.showInputDialog("Enter a letter.");
do{
if (inpt.charAt(0)==word.charAt(x))
{
dashes[x]=inpt.charAt(0);
c++;
}
x++;
}while((inpt.charAt(0)!=word.charAt(x-1))&&(x!=6));
for (int z=0; z<6; z++)
{System.out.print(dashes[z]);}
System.out.println();
}
}while((y<10)&&(!Arrays.equals(dashes, cheque))&&(!guess.equalsIgnoreCase(word)));
System.exit(0);
}
}