Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java Swing Events/Listeners

807607Dec 15 2006 — edited Dec 18 2006
There are two ways to implement Swing Events/Listeners:

1. Have everything in 1 file and have anonymous inner classes that implement the listeners.

2. Have a main GUI class that has separate classes of JPanels that implement the listeners.

I have worked with case 1 where everything is in one file so that I can call functions within the one GUI class when an event is caught. I am having problems with approach 2 because I do not know how to call functions in the main GUI class when an event is caught in the separate JPanel classes.

Right now I have a GUI.java and a TreePanel.java, GUI.java is the main class and contains a panel TreePanel. TreePanel implements TreeSelectionListener and extends JPanel and catches an event. My question is, how do I call a function in the GUI class from TreePanel? Doing a "super" in TreePanel will give me JPanel. Doing getParent() on TreePanel's parent containers until it reaches the JFrame of GUI didn't help because my GUI is not a JFrame.

Any ideas?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 15 2007
Added on Dec 15 2006
3 comments
514 views