Define one ActionListener class. Declare an object of the action class in the UI class. Set each button actionListener using addActionListener method and add this action class reference as param and finally set action command to each of them. – Amarnath
You just need to create new instance of the ActionListener each time. BTW for lots of reasons it is recommended to use Action's instead. Here is nice resource which also explains why you should go with using Actions over ActionListeners, a Java tutori
I'm trying to figure out what i am doing wrong with action listeners. I'm following multiple tutorials and yet netbeans and eclipse are giving me errors when im trying to use an action listener. ...
Post a Comment:
Showing 0 Comments: