This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi 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:
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 Sincerely Shay Gaghe
[This message has been edited by Shay Gaghe (edited October 24, 2001).]
Why are you making seperate classes to hold each GUI element? Normally, you would just add regular JButton/JList to MainClass... this also makes it harder to do event handling normally, because you somehow have to be able to access the GUI elements inside your class to treat them like GUI elements...
Aside from that, the problem is that you are specializing your GUI components too much inside the seperate classes... at the ButtonClass level, ButtonClass shouldn't know that it needs to interface with ListClass... you should handle all of that later in the MainClass... something like this... it is still a little too specialized, though. You really need to just use regular GUI components instead of extending them this way..
Write once, run anywhere, because there's nowhere to hide! - /. A.C.