This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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?
... 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
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Joined: Aug 07, 2002
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.
Joined: Jan 30, 2002
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