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 Collaboration between separate  parts(classes) in the same framework Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Collaboration between separate  parts(classes) in the same framework" Watch "Collaboration between separate  parts(classes) in the same framework" New topic

Collaboration between separate parts(classes) in the same framework

Shay Gaghe
Ranch Hand

Joined: Sep 03, 2001
Posts: 102
I have a Swing interface that I divided into separate classes (20 classes). Each class (that extends Jpanel) of them contains part of the GUI , to collect them i use a main class that instantiate each one of the classes and by running the main class I see all the GUI.
whenever i want one class to effect instance in the another class i use this code(for example i want to add element from one panel(public class) to the another Panel(public class) this how i do it now(each one is a separate public class):

As you can see, unfortunately I use static reference in the ButtonClass to change the state of the list , wish I could use other way to do the same thing without the static keyword (which I really hate , because its unwelcome by OOP design) , what is the appropriate way to do it?
Can I / should I collect those 20 classes to an Applet or Application?
Im developing a chat program that based on sockets . since the client program contains very heavyweight graphics , I wonder if using applet or application makes any different?
Thanks in advance
Shay Gaghe

[This message has been edited by Shay Gaghe (edited October 24, 2001).]
Wilfried LAURENT
Ranch Hand

Joined: Jul 13, 2001
Posts: 269
I think I have already answered to your question some times ago..
Anyway, one solution might be propose a constructor in ListClass which would take a ButtonClass as parameter.
In the ButtonClass, you must add new listener methods to your interface:
public void add/removeActionListener(ActionListener a) {};
When the Button is pushed, then this information is also transfered to the actionListeners of the ButtonClass.
Then in the constructor of ListClass mentioned above, you install the ListClass as an ActionListener of ButtonClass. Yet, the actionPerformed method in ListClass (or an inner class) should be:
public void actionPerformed(ActionEvent e) {
I agree. Here's the link:
subject: Collaboration between separate parts(classes) in the same framework
It's not a secret anymore!