aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes MVC in Swing for a modularised View Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "MVC in Swing for a modularised View" Watch "MVC in Swing for a modularised View" New topic
Author

MVC in Swing for a modularised View

Peter Newman
Greenhorn

Joined: Apr 13, 2007
Posts: 1
Hi everyone,

I've been reading up on MVC, and MVC in Swing and have come to understand Swing's delegate model. However, this current assignment I'm working on, for MVC, the tutor insists on having one controller for the whole application. This would mean removing the controller in the gui (actionPerformed methods) and make the controller implement the actionListener interface, then passing the controller to the view. This is fine by me by all means, but because the way I've designed my gui, I have a bit of trouble getting the view's methods in the controller.

My GUI is actually a JFrame with multiple JPanels with their own classes. So I have a MainView class, a PaymentPanel class, a ProductInfoPanel class, a TransactionPanel class, a FindProductPanel class. The MainView class ties all the panels together like so:



Now the problem is, if I instantiate this MainView class in the controller, I won't be able to access the methods within the Panels to update their components - that is unless I have a getter method for each Panel in the MainView class and call it in the controller e.g. mainview.getProductPanel().setSomeTextField("foo").



Analysing what I've done, my design just seems out of whack for me - something doesn't seem right :/
Could anyone suggest a better way I could integrate MVC, with the way I've designed my GUI?
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1364
    
  17
Hi,

I may be off target with this (warning - entirely untested code follows), but how about something to the effect of:



This keeps your view methods in the view, but all they do is to report back to the controller that the controller can now do controlling things.

Katrina
[ April 14, 2007: Message edited by: Katrina Owen ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MVC in Swing for a modularised View