hey people.i am new to java and i am currently constructing a hangman game. the game asks for the user to enter a word(3 or more characters long). then it prompts the user to enter a single character or the complete word in a message input dialog which contains the word lenght replaced by ("_") .. if the user enters a single character then the dashes are replaced by the character the user enters.if the user enters the right word then a message box appears(correct). i am asking for help at the point where the user is prompt to enter a single character or a complete word.how am i going to reappear the inputdialog with the dashes replaced?how is going to check character by character of the hidden word?thx

import javax.swing.*;

public class StringGame {
    public String word;
     * Creates a new <code>StringGame</code> instance.
    public StringGame() {

public static void main(String [] args){
        StringGameFrame frame = new StringGameFrame();
    StringGame game;
    game=new StringGame();
/** tot is the total amount of characters of a word typed of the user **/ 
	String tot;
    String tot2;
    char cha;
/** the program asks from user to enter a word*/
    String word=JOptionPane.showInputDialog(null,"Please enter a word.");

    String step1;
/** check about word length.if it is equal or less than 2, user is prompted to re-enter a valid word*/
    if ((word.length()<=2)){
    step1= JOptionPane.showInputDialog(null,"Please enter a word with 3 or more characters.");

for (int i=1; i<=word.length() ; i++){
            tot= tot + "_ ";
   String step2=JOptionPane.showInputDialog(null,tot + "\nPlease enter a single character, or a word as your final guess.");
   if (step2.length()<=1){
// !!!!!! FAULTY PART !!!!! 
    for (int i=0;i<=word.length(); i++){
       if (cha.equals(step2)) {
           tot2= tot2 + step2;
       } else{
           tot2=tot2 + "_ ";
   } else {
    if (step2.equals(word)){
              JOptionPane.showMessageDialog(null,"You guessed correctly");
          } else {
             JOptionPane.showMessageDialog(null,"You guessed incorrectly");


Edited by Nick Evan: Wrap your code in [code].. code here .. [/code] tags

7 Years
Discussion Span
Last Post by RunTimeError
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.