DZone Forums
Go Back   DZone Forums > Community > Languages & Frameworks > Java
Reload this Page Desktop Swing App Architecture : 50,000 view
Notices
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  (#1 (permalink)) Old
Member
 
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Dec 2010
Default Desktop Swing App Architecture : 50,000 view - 12-03-2010, 03:05 PM

I feel like this is an age-old question, but I have not found good references for best practices when building a Swing desktop app. There's a decade of books and such for how Swing components work. But how about a 50,000 foot view of the suggested structure of a Swing app?

For example, I assume the idea of having a centralized controller for all open windows (JFrames and JPanels) is advisable. If a JPanel component has a state change, it notifies the parent controller in case any other entities in the app need to know.

So my setup, from parent down to label/button components is:
MyDesktop extends JFrame (the Parent, and controller)
-- spawns JInternalFrame
---- spawns JPanel
------ and that JPanel contains the fields, buttons, labels, etc

Now, let say a JPanel contains a JButton for "Process Orders", and has a JLabel as a status box (like to display Processing order 001, Processing order 002...etc). Clicking the button triggers the JPanel to notify the controller to initiate business logic somewhere else (perhaps through another api). What's the suggested setup for the controller to continuously update the JLabel in the JPanel where the button was clicked? Should MyDesktop have a clear shot all the way down to the JLabel so it can do something like?:

MyDesktop.jInternaleFrameName.jPanelName.jLabelNam e.setSet("Processing 001...")

Or should each child (the JInternalFrame, the JPanel) have updateXXX() methods to "call down" to their children to send the text "Processing 001" to eventually make it to the JLabel?

It seems to me that the controller (MyDesktop in this case) shouldn't even know the JLabel exists, and therefore the "call down" approach is the right way. Or, am I just completely off base with the entire approach? Where's the docs and tutorials for how to architect these things?

Thanks,
Rob
Reply With Quote
  (#2 (permalink)) Old
Member
 
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Jan 2011
Default 01-20-2011, 03:49 PM

Hi Rob,

In several large swing applications I used the approach to have one controller per panel. This greatly improves decoupling and makes you think of components instead of call-hirarchies.
In your example you would have a "process orders controller", which is called from with the actionPerformed() of your processOrders button. The controller might register itself on some backend model object and will be informed about processed orders by some event. Each event will make the controller update the label. There's typically asynchronous work involved.
With this approach, creation and destrucion of panels is always combined with creation/destruction of corrsponding controllers and registering/deregistering the controller to the backend model.

Maybe this ideas hepl you.

Happy coding,
Uli
Reply With Quote
Reply

Tags
architecture, desktop, java, swing

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
software architecture basics suma_eclipse Java 3 10-22-2010 05:23 AM
which is good Dynamic Language or Static in middleware SOA Architecture shakilsoz17ster Patterns & Architecture 0 06-15-2010 07:58 AM
webservice client for a Java Desktop Application NetBeans 6.7.1 samahitha NetBeans 0 11-09-2009 12:12 PM
SOALIB - Service Oriented Architecture Libraries soalib Web Services, SOA & ESB 0 01-04-2009 10:18 PM
Setting an Image as Background in a Desktop Pane nuonical Eclipse 0 09-12-2008 03:44 PM


Copyright 1997-2009, DZone, Inc.
vBulletin Skin developed by: vBStyles.com