JButton我以匿名方式创建了 26个,actionListener
标记为字母表中的每个字母。
for (int i = 65; i < 91; i++){
final char c = (char)i;
final JButton button = new JButton("" + c);
alphabetPanel.add(button);
button.addActionListener(
new ActionListener () {
public void actionPerformed(ActionEvent e) {
letterGuessed( c );
alphabetPanel.remove(button);
}
});
// set the name of the button
button.setName(c + "");
}
现在我有一个匿名keyListener
类,我想根据键盘上按下的字母来禁用按钮。因此,如果用户按下 A,则该A按钮被禁用。考虑到我目前的实施,这甚至可能吗?