This question already has an answer here:
- How do I compare strings in Java? 23 answers
public void keyTyped(KeyEvent e)
{
char typLet = e.getKeyChar();
//String typeLett = Character.toString(typLet);
String typeLett= String.valueOf(typLet);
for(int i = 0;i<4;i++)
{
for(int j=0;j<4;j++)
{
//this if statement will never be true for some reason idk why
if(button[i][j].getText() == typeLett)
{
System.out.println(button[i][j].getText());
//button[i][j].setVisible(false);
//gamePanel.add(button[i][j], 0,j);
}
}
}
}
I'm trying to compare the letter you pressed on the keyboard with the letter that's on the JButton. They're both strings to they should be working fine, however, no matter what I click, the statement will never be true.
Aucun commentaire:
Enregistrer un commentaire