In relation to my previous problem, I now have a new problem. In order to avoid the inner class, my class now implements an actionListener
. My code is as follows:
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);
}
}
How can I effect the listener to my buttons A to Z? Because all it can listen to is the last button which in this case is button Z.
Thank you.