I created 26 JButton in an anonymous actionListener labeled as each letter of the alphabet.
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 + ''); }
Now I have an anonymous keyListener class, where I would like to disable the button based off of which letter was pressed on the keyboard. So if the user presses A, then the A button is disabled. Is this even possible given my current implementation?
Could you not simply declare an array of 26 JButton objects at class level, so that both listeners can access them? I believe anonymous inner classes can access class variables as well as final variables.