"Il y a peu de choses qui me soient impossibles..."
"Il y a peu de choses qui me soient impossibles..."
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Campbell Ritchie wrote:Sounds like what we usually discuss in the Swing forum, so I shall move you there.
"Il y a peu de choses qui me soient impossibles..."
Jelle Klap wrote:Well, you could clean up the view by making the controller responsible for event handling.
"Il y a peu de choses qui me soient impossibles..."
Stevens Miller wrote:
Jelle Klap wrote:Well, you could clean up the view by making the controller responsible for event handling.
How would I go about doing that? Unless the controller includes the button as a member (which is what my Question 2 is about), how would it react to user-input events?
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Jelle Klap wrote:
Stevens Miller wrote:
Jelle Klap wrote:Well, you could clean up the view by making the controller responsible for event handling.
How would I go about doing that?
By having a controller implement the appropriate interface or extend an adapter, and adding it as a listener of view component.
"Il y a peu de choses qui me soient impossibles..."
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Jelle Klap wrote:In your example have Controller implement ActionListener and in you buildGUI() method add the controller instance as an action listener to the button: button.addActionListener(controller); - note that the buildGUI(); invocation in the ConcreteView constructor should take place after setting the controller.
"Il y a peu de choses qui me soient impossibles..."
May I Merge MVC's View and Controller?
Rob Camick wrote:Check out the 5th paragraph in How to Use Models.
"Il y a peu de choses qui me soient impossibles..."
Stevens Miller wrote:
Jelle Klap wrote:In your example have Controller implement ActionListener and in you buildGUI() method add the controller instance as an action listener to the button: button.addActionListener(controller); - note that the buildGUI(); invocation in the ConcreteView constructor should take place after setting the controller.
I get you. Now, that would work fine for my one-button example, but what happens when there are many buttons? If each adds the same controller as its ActionListener, there's going to have to be a big switch statement in the controller's actionPerformed method.
Also, neither of these approaches makes much difference to my central concern: what's the point of separating the controller from the view, if user-input events are initially processed by view code?
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
WARNING! Do not activate jet boots indoors or you will see a tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
|