• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MVC in Swing for a modularised View

 
Peter Newman
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1367
18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic