• Post Reply Bookmark Topic Watch Topic
  • New Topic

MVC Layout - Which way to add listeners is better?  RSS feed

 
Matt Jango
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I'm doing a basic MVC layout for a pretty basic game that I am making in order to understand the whole MVC layout. The game requires the user to move up/down/left/right via JButtons on the GUI. Since I'm using an MVC layout and my buttons are in a different class than the ActionListeners, I was wondering what the best way to add the action listeners are?

Method 1:

View Class ActionListener method:


Control Class add ActionListener method:



Method 2:

View Class ActionListener method:


Control Class add ActionListener method:




Which method is better? Is there another method that is even better than these two? Let me know! Trying to get this MVC thing down . (Any other suggestions welcome as well)!
 
Stephan van Hulst
Saloon Keeper
Posts: 6984
110
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would just put the listeners in your view class. There's no real point in letting other classes attach custom listeners to the buttons of your GUI. In many cases Control and View are handled by the same classes.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!