I have an ActionListener in a class extending JFrame. On button click I need to set the visibility of JFrame extended objects created in a Main class. In this example, clicking the button will make the existing object with that button become non-visible and it will make another JFrame object become visible.
The ActionListener is inside of one JFrame class, the object is created inside the Main class. How can I run the method of that specific object within the Main class from the ActionListener inside the JFrame class?
I already have a setVisibility method, but am unclear on how I can direct the ActionListener to run this method on an object that exists inside another class.
In Main Class:
Object1 jFrameObj1 = new Object1();
Object2 jFrameObj2 = new Object2();
In Object1 Class (inside action listener):
if(event.getSource() == button){
jFrameObj1.setVisible(false);
jFrameObj2.setVisible(true);
}