Without a long look at there whole thing it's hard to be very specific, but in general:
If you divide your application into smaller and smaller components (classes, methods etc) then each of those components becomes simpler and easier to understand (which is good) until eventually you reach a point where the components are too small and simple. You know you're reached that point when you have to pass long strings of parameters between the methods or constructors.
The theory behind this is "cohesion and coupling" - have a quick look at this: http://en.wikipedia.org/wiki/Low-Coupling_/_High-Cohesion_pattern
For methods typical guidelines say thing say things like: anything method over 100 lines, or with {} nested more than 4 deep should be split up. (Big exception: the tedious init methods that build GUI interfaces - they are intrinsically long)
For classes, each class should represent just one thing. For every program I've seen with too many classes, I've seen 100 with too few classes. Don't be afraid of creating many classes.
JamesCherrill
... trying to help
8,527 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,456
Skill Endorsements: 30
...neither should you make a program that continuously creates a new instance every time a new panel is added - what would happen if I'd open 1000+ panels at the same time (it would get really slow if you don't get a heap overflow).
Let's be sensible here. Each panel will involve a number of instances of Swing classes, so anything you do with your own classes will be pretty much irrelevant. As for 1000+ panels - why don't you leave that problem until something suggests you will encounter it. How many panels do you expect?
Remember also that in the end you have to create enough "stuff" to handle the requirements of the application. Much of this "stuff" will have multiple instances. The smaller your classes, the less the redundant "stuff".
Here are some of the classes I'd expect to see in an app like this:
Client:
Main class - app startup and controller (one instance)
Network comms class - handling sockets, connections etc (one instance)
Main window (one instance)
Conversation panel (many instances)
Server:
Main class - app startup and controller (one instance)
Socket listener (one instance)
Connection handler (many instances)
Main window (one instance)
Conversation panel (many instances)
Plus numerous inner classes for ActionListeners etc
... but when developing the code there will probably be other service classes that emerge from the detailed design, such as (maybe) User - encapsulates info about user identity/logon/rights etc., Conversation - encapsulates info about who is talking to who via which connection.
JamesCherrill
... trying to help
8,527 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,456
Skill Endorsements: 30