• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

MVC question

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello.
I've been thinking in the MVC patern and I think ther is something that's missing me.
As far as I can see this patern concerning the assignment, the model will have a array of Objects[][] to be filled with the data from the table. Only two methods here, the getData and setData. The View will be the GUI and the controller will have all the methods to make the reservation, search the database, and will also be responsable for filling the array in the Model.
Am I right? I'm with this, and each post that I read concerning this makes me more confused.
Thanks,
Miguel
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It sounds pretty good to me.
Mark
 
Miguel Roque
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Mark.
Thanks for your repply.
I've been out due to some problems, but here I am again. One last question. In the MVC, the View uses the controller to register the actions. When a action is made, the Controller informs the Model that after that updates the View.
This means that the view don't know anything on the controller. The controller knows everything of the Model, and the Model must know a bit of the View (knows the method that updates the GUI)!
Is this correct?
My idea is to create a class that implements the ActionListener interface as a controller. The Model has the methods to make the Search, Reservation, etc... the idea of the Model could be a be a DatabaseFacade. After any method in the DatabaseFacade has been processed, we can call a method in the GUI like "dataChanged(Object[][]) that updates the JTable.
Comments please.
Thanks,
Miguel
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

My idea is to create a class that implements the ActionListener interface as a controller.


I wouldn't do that, what if you want to catch a Keyboard action from the GUI, then your controller can't do that, the Listeners need to be Anonymous Inner classes inside the controller.
Also the Model should not know about the view either. Usually the model will change based on a call from the controller to the DataAccess class, and therefore knows that it is having the Model change, so it can send the model to the view for the model.
Mark
 
Miguel Roque
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello again.
I've implemented my MVC as follows:

The main window implements this interface and also the ChangeListener.
The controller implements ActionListener for the buttons and ListSelectionListener for the JTable, and all the actions in the main window have a name defined using "setActionCommand". The controller, when receives a action checks the event.getActionCommand and then calls the methods defined in the FBNControllerInterface for the main window and sends the commands to the model.
After a command is executed, the model fires the ChangeListener and updates the view.
Everything is working OK, but now I need is your comments on this MVC implementation. I'm counting on you guys .
Thanks,
Miguel
P.S. - I'm about to go on weekend , and the weekend is for fun , so I will only get back here on Sunday evening.
 
Miguel Roque
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello.
No coments? May I assume that this is OK?
Please revert.
Miguel
 
The longest recorded flight time of a chicken is 13 seconds. But that was done without this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic