How do you change between views in MVC java?

Viewed 43

I've been using this implementation of the MVC pattern. I wanted to know how to navigate between different 'pages'(i.e views).This is my current setup:

MasterController
|             |
ControllerA   ControllerB
  |             |
  ViewA         ViewB
  ModelA        ModelB

where ViewA and ViewB are embedded in MasterController's MasterView(using CardLayout)

What I wanted to do is have a button in ViewA, which when clicked, passes some data to ModelB(through ControllerB) and changes to ViewB.

How would I achieve this? Am I implementing the idea of MVC wrong? My main concern is that putting all Controller code in a single Controller class is a bad idea, and I want different pages to have a different controller code, in order to seperate the application logic of each page into its own class. Should I use some other pattern here? How would you implement MVC in Swing to navigate between different Views and subviews?

0 Answers
Related