Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Gary Fletcher
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
K. Tsang
Bartender
Posts: 3610
16
Firefox Browser Java Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?)
 
Sam Gooding
Ranch Hand
Posts: 35
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gary Fletcher
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!