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?
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.
Joined: Sep 03, 2001
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
Joined: Jan 09, 2001
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.