aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes listening to strangers ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "listening to strangers ?" Watch "listening to strangers ?" New topic
Author

listening to strangers ?

Shay Gaghe
Ranch Hand

Joined: Sep 03, 2001
Posts: 102
hi
please take a look:

The External is the main class , I want the External class to listen to all the events that occur on the ControlPanel, how can I do it? And can this method decreas the listening performance?
thanks
Vinod Venugopal
Ranch Hand

Joined: Dec 06, 2000
Posts: 148
Add action listeners ( for button )or whatever listeners are required for the components in ControlPanel in the ControlPanel class itself. Since you are passing reference of Control Panel to GUI manager & gui manager reference to External , so all events will be handled accordingly.
I wonder what listening performance you are talking about?


- Vinod<br />-------<br />SCJP2
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Shay,
It is usually not a good idea to do it the way you are explaining because from a maintenance and debugging standpoint it could easily become unmanageable. The controlPanel should handle its own events. You may have the listener methods call some other routine that may exist in another class.
To perform what you are explaining will mean that you must pass in a reference for External into ControlPanel. That means that you will need constructors for GUIManager that accept External and one in ControlPanel that accept External. Then inside ControlPanel you can go ahead and add External as a listener for events.
Now that you have that, you will need some way to get the references to the objects themselves once inside your External listener method (since they are not local to External). To do this you will need to create accessor methods, such as: getButton1() etc.
See how this is easily becoming a nightmare ...
Imagine being the programmer who later has to add one single control to this mess! Talk about OOP exceptions ...
Regards,
Manfred.
Shay Gaghe
Ranch Hand

Joined: Sep 03, 2001
Posts: 102
Thanks for the reply
i did it that way:

is that what you mean?
(you said) :
Now that you have that, you will need some way to get the references to the objects themselves once inside your External listener method (since they are not local to External). To do this you will need to create accessor methods, such as: getButton1() etc.
///

I didn’t understand this section of you expiation. Just for the record im developing a chat program RMI based , as you see the ControlPanel class and other XXXPanel will be a co-component inside GUIManager.
In External class I extends Jpanel only to show the GUIManager’s components , I don’t have any graphic controller inside External just method to request the server, therefore I wonder what accessor methods do you mean?
Since my client also have a local Hashtable to store all the client’s information I wonder if your structure will not cuz NullPointerException when I request a particular entry?
Thanks a lot
Shay
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Shay,
It looks good. The part that we don't seem to be connecting with has to do with what you are going to do inside your requestLogin method. If you need to for example get some text from a textField that happens to be inside your ControlPanel then you would need a way to get a reference to the textfield from the External class. This is usually accomplished by accessors. If you don't require any inputs from any ControlPanel GUI objects then all is well ...
Regards,
Manfred.
Shay Gaghe
Ranch Hand

Joined: Sep 03, 2001
Posts: 102
Thanks a lot Manfred!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: listening to strangers ?