posted 16 years ago
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?