Java Hangman Project: Action Listener
问题 I am creating a hangman game. I made a button A - Z using the GUI Toolbars in Netbeans as follows:. My problem is, how can I add an actionlistener to all of it. Is it possible to use a loop? If i click the button A, i will get the character 'a' and so on.. 回答1: Yes it is possible to use a loop, but since your JButtons were created by using NetBeans code-generation, they won't be in an array or collection initially, and so this is something that you'll have to do: create an array of JButton