I have a main class in a program that launches another class that handles all the GUI stuff.
In the GUI, i have a button that i need to attach an ActionListener to.
The only problem is, the code to be executed needs to reside within the main class.
How can i get the ActionPerformed() method to execute in the main class when a button is clicked elsewhere?
Make your controller (“main” class) implement the ActionListener interface, then pass a reference to the view class:
It can also be done with Actions, but that’s more useful where you want one piece of code to respond to many buttons.