I want to use MVC to structure my Swing application, but there seems to be a conflict.
As I understand MVC, the controller should handle input and update the model. The model should notify its observers of which the view is one.
I have two problems
- Swing is all part of the view. The fact that components have their own models is an implementation detail. I want to keep the swing-specific code out of the controller/model don't I?
- My controller needs to receive user-triggered events, but these come from the swing component which is in the view, and the controller shouldn't know about the view.
I'm sure this problem has been solved many times before, but I can't find a real world example of an MVC based swing app of a decent size.
Update - A problem I forgot
What MVC doesn't directly cater for is the structure of the various MVC components within the hierarchy of the application. For example, the main display may have "sales" and "purchasing" tabs, each of which might have "new" and "query" panels. On top of that, there may be an "amend selected" button which would create (possibly multiple) windows on request.
Something has to create a model,view and controller for these sub-components on request. It can't be the controller since the controller or model since they don't know which view to create and it shouldn't be the view since it's application logic and it's responding to an event (which is the controller's job).
Is there an answer?