【发布时间】:2008-11-13 09:38:28
【问题描述】:
我在匿名actionListener 中创建了 26 个 JButton,标记为字母表中的每个字母。
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 按钮将被禁用。考虑到我目前的实现,这甚至可能吗?
【问题讨论】:
标签: java swing actionlistener keylistener