I am making a hangman game where if I guess the wrong letter of the word in aLetter I add 1 onto the label inCorrect, however this code is adding 1 onto inAccurate when I guess correctly aswell. How can I fix this?
public class Form extends javax.swing.JFrame {
String FindWord = "apple";
int w = 0;
}
private void attemptSignActionPerformed(java.awt.event.ActionEvent evt) {
int charPos = 1;
String letter = aLetter.getText();
charPos = FindWord.indexOf(letter);
myMessage.setText("position is " + charPos);
if (charPos == 0) Char0.setText(letter);
if (charPos == 1) Char1.setText(letter);
if (charPos == 2) Char2.setText(letter);
if (charPos == 3) Char3.setText(letter);
if (charPos == 4) Char4.setText(letter);
if (charPos == 5) Char5.setText(letter);
charPos = FindWord.indexOf(letter, charPos + 1);
if (charPos == 0) Char0.setText(letter);
if (charPos == 1) Char1.setText(letter);
if (charPos == 2) Char2.setText(letter);
if (charPos == 3) Char3.setText(letter);
if (charPos == 4) Char4.setText(letter);
if (charPos == 5) Char5.setText(letter);
Below is the part that i'm having trouble with
if (charPos == -1) {
w++;
inCorrect.setText(Integer.toString(w));
}
}
I want to only add 1 onto inCorrect when the letter I guess is not in the word "apple".