This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

MVC in Swing for a modularised View  RSS feed

 
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?
 
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 ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!