File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Handling Child events in Parent? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Handling Child events in Parent?" Watch "Handling Child events in Parent?" New topic

Handling Child events in Parent?

Akshay Kumar
Ranch Hand

Joined: Feb 24, 2004
Posts: 37

how to handle child events in parent when both having separately implemented listeners?

Problem 'm facing:
i've an Applet and i created two classes(each extends AWT Panel and implements ActionListener) as "Pan1" and "Pan2". Onloading of the applet, "Pan1" is instantiated and made visible after adding into applet. "Pan1" contains a button. Actually, when i click on this button "Pan2" should be created and made visible which contains some other controls.

here, how'll i listen for the events of "Pan1" in applet and to load "Pan2" into applet itself. Inturn both those panels implements listeners to act internally.

hope 'm clear. if possible, can come out with sample code. Or if there any other approach.
clio katz
Ranch Hand

Joined: Apr 30, 2004
Posts: 101
seems several options are possible:

panel1 "show panel2" button
. implement actionlistener as anonymous inner class
. implement special actionListener class
. associate an AbstractAction-derived class
. etc

parent can also be the listener for this component...

possible panel2 display strategy
. if layout/screen real estate is fixed,
you could instantiate an invisible panel2,
and have the button trigger _setVisible

can you post some code?
I agree. Here's the link:
subject: Handling Child events in Parent?
It's not a secret anymore!