Get letter pressed from JButton
when pressed
public class ButtonDisabler implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
JButton btnGetText = (JButton) e.getSource();
char charLetterPressed;
charLetterPressed=(btnGetText.getText().charAt(1));
btnGetText.setEnabled(false);
}
}
Then use that letter and compare it to a string, then display the letter only if found into a JLabel
char charChkWord;
StringBuffer word = new StringBuffer();
for (int i = 0; i < strRandomWord.length(); i++) {
charChkWord = strRandomWord.charAt(i);
if (charLetterPressed == String.valueOf(charChkWord)) {
lblWord.setText(word.append(charChkWord).toString());
}
}
I'm not sure how to get that letter and compare it to the string.