Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A Beginner's Guide to Decoupling a GUI

 
Mark Waes
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm new here and like the friendly feeling to this forum, so I thought I'd ask for a little help.

I'm creating a simple program with a GUI I've built using the NetBeans IDE.

I would like to understand some basic techniques for decoupling a UI from the objects which it's based upon. I've done some reading with regards to MVC, but much of what I've read seems aimed slightly above my level for the moment.

I have a simple class designed to calculate the linear expansion of a substance depending on what it is and the temperature range applied. Here's my class so far:



This page (flickr) shows my GUI I have so far. The application is working currently, but all the logic is contained in the form's class.

Any recommendations of how I should proceed?

Thanks in advance

Mark
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

Try this example: Model-View-Controller (MVC) Structure. It's one of the more user-friendly ones I've seen on the web.

It looks like you already have your model and view pretty well established, so you just need to create a controller. Basically, the controller is the piece that "connects" the model and the view, passing messages back and forth as needed.

In setting up the controller, ask yourself: When something changes in the view, does the model need to know about it? And when something changes in the model, does the view need to be updated?
 
Mark Waes
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I'll give it a go...
 
Mark Waes
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There seems to be a fair amount of variability for how to achieve this. These two diagrams capture my thoughts so far:



or



The model appears to be unique to the view in most cases, but for my situation I would like any changes in the model to by automatically updated to any view which is representing it, whther using the same controller or not.

Actually, the link Marc provided was a great help, other than this point (unless I missed it).

And I understanding the concept of MVC correctly, or missing the point completely?

Thanks

Mark
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but for my situation I would like any changes in the model to by automatically updated to any view which is representing it

Then the view must register some type of state listener on the model so that it is notified whenever the model's state changes.
[ September 26, 2008: Message edited by: pete stein ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic