关于我的previous problem,我现在有一个新问题。为了避免内部课堂,我的课程现在实现了actionListener
。我的代码如下:Java实现ActionListener问题
public class MainGame extends JDialog implements ActionListener {
public MainGame(JDialog owner) {
super(owner, true);
initComponents();
jPanel1.setLayout(new GridLayout(3, 9, 3, 5));
for (char buttonChar = 'a'; buttonChar <= 'z'; buttonChar++) {
String buttonText = String.valueOf(buttonChar);
letterButton = new JButton(buttonText);
letterButton.addActionListener(this);
jPanel1.add(letterButton);
}
newGame();
}
public void actionPerformed (ActionEvent action){
if (action.getSource() == letterButton) {
letterButton.setEnabled(false);
}
}
我该如何影响听众对我的按钮A到Z?因为它所能听到的全部是最后一个按钮,在本例中为按钮Z.
谢谢。
我怎么能这样做? – newbie 2011-01-30 15:05:15
等待我看到你的问题,让我编辑我的答案。 – jzd 2011-01-30 15:08:28