0

when one builds an MVC structure, in Java Swing, are you supposed to add the button listeners in the view and listen to them in the Controller?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Karl
  • 57
  • 5
  • Yes, I think...your question isn't really clear. – Tim B Aug 14 '14 at 13:15
  • 1
    Have the UI create its own listeners and have them call methods of the controller, *or* have the controller create the listeners, and have the UI ask the controller for them and register them to buttons. The former provides better isolation between UI and controller, the latter is sometimes less tedious to code. Just make sure you are consistent in your choice throughout your application. – Jason C Aug 14 '14 at 13:31
  • More [here](http://stackoverflow.com/a/3072979/230513). – trashgod Aug 14 '14 at 15:01

1 Answers1

2

I think it's not a good idea to transfer the processing of the low-level Swing-events into controller. Your controller should be framework independed (as far as possible). So if user clicks a button, your view just calls an appropriate method of controller. In some cases you can also convert a low-level swing event into a high-level event and controller can listen to it. Also view can handle all the internal logic without to call the controller (for example if one checkbox/radio button enables another widget).

Sergiy Medvynskyy
  • 11,160
  • 1
  • 32
  • 48