JButton
按下时获取字母
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);
}
}
然后使用该字母并将其与字符串进行比较,然后仅在找到该字母时才显示该字母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());
}
}
我不确定如何获取该字母并将其与字符串进行比较。