• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is right,MVC?

 
shao zhimin
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I,m writting my GUI, but doubt that the MVC pattern. now i design three panel -- searchingPanel, bookingPanel and JTable, i have a question that searchingPanel bookingPanel is View or controller??
now i have a ActionController (but not implements ActionListener). searchingPanel and bookingPanel implements ActionListener. when an user event occur, its call the methods of ActionController. is it rigtht?? i only one controller?
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shao,

... i have a question that searchingPanel bookingPanel is View or controller??
now i have a ActionController (but not implements ActionListener). searchingPanel and bookingPanel implements ActionListener. when an user event occur, its call the methods of ActionController. is it rigtht?? i only one controller?

Your two panels exhibit traits of both view and control, which is very common for swing's idea of MVC. The view and control are usually tightly coupled. I would not worry too much about the exact semantics of your implementation so long as it is clear and functions well. I used a completely unorthodox approach for control, using a java.beans based Mediator pattern and scored perfect on the GUI. So, as long as your ActionControler is well designed and decouples the the two panels from your other GUI components you should not have anything to worry about.
Hope this helps,
Michael Morris
 
shao zhimin
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Michanel, but now i consider that the ActionController extends ActionListener and all the user event are dealed in the controller. i have another question that how to distinguish the different event?? use getActionCommand() methods or the other method?
the reason what i to do that i look some posts in the forum and someone use one Controller, but i do not well it.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shao,
When I had multiple components using the same ActionListener, I used getActionCommand() from the ActionEvent to distinguish where the event originated. That's usually the simplest way and is perfectly accepatable.
Hope this helps,
Michael Morris
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic