• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

MVC JButton List

 
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am stumped on how to do this....I am going back and changing some legacy code to make it cleaner.

I am trying to use the MVC architecture within swing. I do understand that swing doesn't allow a full implementation of the MVC architecture. I use a list to create the buttons because the list can change at runtime based on the amount of categories a user creates. When the application starts it loads the categories and sets the name of each category to the button.

My question is how would I separate this into the view, model and controller? I do know that I would need some sort of listener to notify the model that the user added a new category.


 
Saloon Keeper
Posts: 15510
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You say the application loads the categories at startup. In this case you don't need listeners, just do what you have now.

The most important part of MVC is that your business logic layer does not know about your presentation layer. In the most loosely coupled scenario, your presentation layer also doesn't know about your business logic layer, and controllers just hand them buckets of data with which to construct the view (these buckets are called "view models"). How far you should separate these layers depends on the complexity of your application. In small applications it's not a big deal to have the view use business objects rather than view models.

Note that you don't have to use observers to achieve MVC in Swing. Only if your business layer operates independently from your controllers (for instance, when it's some sort of simulation running its own threads). Otherwise, your controller can operate on the business layer, after which it tells the view which parts to update. In Swing, these controllers come in the form of listeners added to your controls. You can just embed these in your presentation layer. If you want a more clear separation, you can bundle "requests" in a controller, and have the controller add simple listeners to the view, calling the controller requests:




 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic