Your code is too messed up to work with. You need to make a clean start.
First you need to think about and create a design for what the code should be doing.
Trying to change junky code is a waste of time.

I agree with Norm, you should start a new method from scratch.

Start with your loop. You know you need a certain number of letters. It doesn't matter what they are, just how many. So make that your loop condition.

Then decide what you need to do with the input letter. If you want to keep them, put them in an array. There are functions in the string class that can make things upper or lower case, so think about how that can be used to make your comparisons easier. You shouldn't have to hard-code every one of your letter checks. Use your array.


That should give you some things to work on.

I don't think I said it enough..."I don't have enough time to re-do it". Can you PLEASE just try to get this working so I can see how to use it?

I think you are confused. We're not hired help. We're here to help YOU learn how to program. You learn by trying and trying and trying. When you have problems, post them here and we'll help you get the code to work.

What changes have you made to your code in the last two days?
We've suggest an approach to take for you to solve your problem.

> I don't think I said it enough.
I think you've said it plenty and you're blatantly ignoring what you've been told. The code is a wreck and you are going to have to re-write it if you want it to work at all.

I haven't made changes because I've been trying the returning over and over. I've probably tried 20 times by now...

You've been trying over and over, but haven't made changes? How do you figure that is going to work out?

I've been trying the returning over and over

If you get errors, copy and paste the code and the full text of the error message here.

I've been trying returning but I still have no clue how to make it work properly.

public static void main(String[] args) {
    
    int x = 10;
    
    STAND();
    WORD1(x);
    WORD2();
    
  }
  
  public static void WORD1(int y) { //Java
    char key = ' ';
    
    c.setFont(new Font("arial", Font.PLAIN, 50));
    c.setColor(Color.BLACK);
    c.drawString("_", 251, 472);
    c.drawString("_", 287, 472);
    c.drawString("_", 322, 472);
    c.drawString("_", 357, 472);
    
    while(key != 'J' || key != 'A' || key != 'V' || key != 'j' || key != 'a' || key != 'v')
    {
      key = c.getChar();

      if (key == 'J' || key == 'j')
      {
        c.setFont(new Font("arial", Font.BOLD, 50));
        c.setColor(Color.BLACK);
        c.drawString("J", 250, 470);
      }
      else if (key == 'A' || key == 'a')
      {
        c.setFont(new Font("arial", Font.BOLD, 50));
        c.setColor(Color.BLACK);
        c.drawString("A", 285, 470);
        c.drawString("A", 355, 470);
      }
      else if (key == 'V' || key == 'v')
      {
        c.setFont(new Font("arial", Font.BOLD, 50));
        c.setColor(Color.BLACK);
        c.drawString("V", 320, 470);
      }
      else if(key != 'J' || key != 'A' || key != 'V' || key != 'j' || key != 'a' || key != 'v')
      {
        COUNTER();
        
        if(counter == 11)
        {
          c.clear();
          c.setFont(new Font("arial", Font.PLAIN, 25));
          c.setColor(Color.BLACK);
          c.drawString("You          him! Try the next word!", 125, 250);
          c.setColor(Color.RED);
          c.drawString("killed", 174, 250);
          
          c.setFont(new Font("arial", Font.PLAIN, 15));
          c.setColor(Color.BLACK);
          c.drawString("The next word will automatically start in 5 seconds.", 150, 275);
          
          WAIT();
          c.clear();
          counter = 0;
          STAND();
          WORD2();
        }
      }
    }
    return;
  }

Under what conditions/when is the return statement executed?

Sorry, I really have no clue and I've never used returning as I'm new to programming more advanced things.

The question is: Is the return statement ever executed?
Add a: System.out.println("Returning");
in front of it to see if it is executed.
Does your code ever EXIT the while loop?

No it is not.

If you have never used return in your code before, Here's a tip;
Go through the code that you have written. Then imagine the steps being executed in your mind 1 by 1.. Slowly you will come down to a point where the USER made SOO many wrong predictions that its time to end.

the statement return is most likely(in this case ) telling the program to stop taking input and exit from the method(ie: When the hangman is 'HANGED'.).
;)

That is where your return; statement should be placed.

The hanging works fine. It goes to the next word if they mess up too much, but the problem is going from one word to another when the person has filled out all correct letters.

I've tried changing the while statement and then adding the WORD2() bit at the end. Would this work?

public static void WORD1() { //Java
    char key = ' ';
    
    c.setFont(new Font("arial", Font.PLAIN, 50));
    c.setColor(Color.BLACK);
    c.drawString("_", 251, 472);
    c.drawString("_", 287, 472);
    c.drawString("_", 322, 472);
    c.drawString("_", 357, 472);
    
    while(counter <= 11)
    {
      key = c.getChar();

      if (key == 'J' || key == 'j')
      {
        c.setFont(new Font("arial", Font.BOLD, 50));
        c.setColor(Color.BLACK);
        c.drawString("J", 250, 470);
      }
      else if (key == 'A' || key == 'a')
      {
        c.setFont(new Font("arial", Font.BOLD, 50));
        c.setColor(Color.BLACK);
        c.drawString("A", 285, 470);
        c.drawString("A", 355, 470);
      }
      else if (key == 'V' || key == 'v')
      {
        c.setFont(new Font("arial", Font.BOLD, 50));
        c.setColor(Color.BLACK);
        c.drawString("V", 320, 470);
      }
      else if(key != 'J' || key != 'A' || key != 'V' || key != 'j' || key != 'a' || key != 'v')
      {
        COUNTER();
        
        if(counter == 11)
        {
          c.clear();
          c.setFont(new Font("arial", Font.PLAIN, 25));
          c.setColor(Color.BLACK);
          c.drawString("You          him! Try the next word!", 125, 250);
          c.setColor(Color.RED);
          c.drawString("killed", 174, 250);
          
          c.setFont(new Font("arial", Font.PLAIN, 15));
          c.setColor(Color.BLACK);
          c.drawString("The next word will automatically start in 5 seconds.", 150, 275);
          
          WAIT();
          c.clear();
          counter = 0;
          STAND();
          WORD2();
        }
      }
    }
    c.clear();
    counter = 0;
    STAND();
    WORD2();
  }

Scratch that, the while loop wouldn't work. What would?

Again, start with a simple program that uses a while loop and get that to work before trying to make the mess you have work.

Get rid of the GUI method calls and anything else not related to the getting input from a user and the while loop.

For example - Get this to work:

public static void WORD1() { //Java
    char key = ' ';
    int counter = 0;
     
    while(counter <= 11)
    {
      key = c.getChar();

      if (key == 'J' || key == 'j')
      {
      }
      else if (key == 'A' || key == 'a')
      {
      }
      else if (key == 'V' || key == 'v')
      {
      }
      else if(key != 'J' || key != 'A' || key != 'V' || key != 'j' || key != 'a' || key != 'v')
      {
        
        if(counter == 11)
        {
            return;
        }
      }
      counter++;
    }

  }

I know there is a way to get my code working, and that's what I'd like to stick with. I don't have enough time to re-write a whole new program...afterall I am a beginner.

YOu need to debug your code and find how it is working and see if it is doing what you want it to do. One way to debug your code is to add LOTS of println statements to show variable values and control flow. Then look at the printed output and see where the problem is. If some things are being printed that should NOT be, then look at the logic of the program to see why the println that output that line was executed.

For example looking at the code I posted, what are the valid values for key at line 20?
Are there any values that key should NOT have when the code executes line 20?

I'll try with your code and the debugging.

I changed the WORD1() method to this but it still wouldn't move to the next word (WORD2()) after filling out the entire word:

public static void WORD1() { //Java
    char key = ' ';
    
    c.setFont(new Font("arial", Font.PLAIN, 50));
    c.setColor(Color.BLACK);
    c.drawString("_", 251, 472);
    c.drawString("_", 287, 472);
    c.drawString("_", 322, 472);
    c.drawString("_", 357, 472);
     
    while(counter < 11)
    {
      key = c.getChar();

      if (key == 'J' || key == 'j')
      {
        c.setFont(new Font("arial", Font.BOLD, 50));
        c.setColor(Color.BLACK);
        c.drawString("J", 250, 470);
      }
      else if (key == 'A' || key == 'a')
      {
        c.setFont(new Font("arial", Font.BOLD, 50));
        c.setColor(Color.BLACK);
        c.drawString("A", 285, 470);
        c.drawString("A", 355, 470);
      }
      else if (key == 'V' || key == 'v')
      {
        c.setFont(new Font("arial", Font.BOLD, 50));
        c.setColor(Color.BLACK);
        c.drawString("V", 320, 470);
      }
      else if(key != 'J' || key != 'A' || key != 'V' || key != 'j' || key != 'a' || key != 'v')
      {
        
        COUNTER();
        
        if(counter == 10)
        { 
          
          LOST();         
          WAIT();
          c.clear();
          counter = 0;
          STAND();
          
        return;
        }
      }
    }
  }

public static void LOST() {
    
    c.clear();
    c.setFont(new Font("arial", Font.PLAIN, 25));
    c.setColor(Color.BLACK);
    c.drawString("You          him! Try the next word!", 125, 250);
    c.setColor(Color.RED);
    c.drawString("killed", 174, 250);
          
    c.setFont(new Font("arial", Font.PLAIN, 15));
    c.setColor(Color.BLACK);
    c.drawString("The next word will automatically start in 5 seconds.", 150, 275);
    
  }

public static void COUNTER() {
    counter = counter + 1;
    
    if(counter == 1)
    {
      HEAD();
    }
    else if(counter == 2)
    {
      BODY();
    }
    else if(counter == 3)
    {
      LEFTLEG();
    }
    else if(counter == 4)
    {
      RIGHTLEG();
    }
    else if(counter == 5)
    {
      LEFTARM();
    }
    else if(counter == 6)
    {
      RIGHTARM();
    }
    else if(counter == 7)
    {
      LEFTHAND();
    }
    else if(counter == 8)
    {
      RIGHTHAND();
    }
    else if(counter == 9)
    {
      LEFTFOOT();
    }
    else if(counter == 10)
    {
      RIGHTFOOT();
    }
  }

For example looking at the code I posted, what are the valid values for key at line 20?
Are there any values that key should NOT have when the code executes line 20?

Did you ever look at and think about this question?

Look at your code. What values can the variable key have when the code executes line 36?

You still need to work with a small simple program and get an understanding of the logic to use for if conditions.

Here's a sample of a simple test program:

// Simple program to test if condition

public class TestIfCondition {
  public static void main(String[] args) {
     char[] letters = {'a', 'b', 'c', 'd', 'e', 'j', 'k', 'v', 'A', 'B', 'J', 'K', 'V'};
   
     for(int i=0; i < letters.length; i++) {
        char key = letters[i];    // get the next letter
        // test the letter
        if(key != 'J' || key != 'A' || key != 'V' || key != 'j' || key != 'a' || key != 'v')  {
          System.out.println("true for " + key);
        }else {
          System.out.println("false for " + key);
        }
      }  // end for(i) thru letters  } // end main
} // end class
commented: Still banging your head against this wall? :) +15
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.