Forums Register Login

What is the best OO design for Swing/windowed application?

+Pie Number of slices to send: Send
Mornng

I am currently learning Swing and am wondering what is the best way to approach designing a windowed application. The book I am following doesn't seem to use a single design structure so I would appreciate any guideance from the experts.

Currently I am using the following design method - the names of the classes below are arbitary and for example only:

main


FrameClass


PanelClass


I am unsure if the above would be suitable for an application with multiple windows as it only uses a single frame. Would it be more appropriate to encapsulate a window/frame into a single class as:

FrameClass


Which approach is better, if any, or what other approaches should be used for best OO design?
1
+Pie Number of slices to send: Send
The component-based approach is one way to go, which you seem to be on the right track. Depending on what your app does and how complex, the packaging by function may be another way.

Back to the components. Frame, panel, action or listener can all be their own class. Yet interacting these components or classes will be determined during your design phase (eg do I need abc panel know xyz action/listener?)
1
+Pie Number of slices to send: Send
I also think it looks good . There's no reason to encapsulate everything in a single class ; the only time I do that is if the classes need privileged access to each other members. Even though your has more than one JFrame containing other components, that doesn't mean that should drive the actual composition of the JFrame. For my money, breaking each coherent unit into a different class or method is always preferred because it maximizes code comprehensibility. I think what you're doing looks great.
+Pie Number of slices to send: Send
Thanks for the input. Using individual classes for each compnent really helps to keep the code clean.

If anyone else has suggestions please feel free.

Many thanks
It's weird that we cook bacon and bake cookies. Eat this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 619 times.
Similar Threads
JFrame decorations aren't working
LookAndFeel changing program will not work?
JScrollPane knob won't change size
gridlayout with combo box
Swing Look and Feel not working
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 00:18:16.