aspose file tools*
The moose likes Beginning Java and the fly likes A Beginner's Guide to Decoupling a GUI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A Beginner Watch "A Beginner New topic
Author

A Beginner's Guide to Decoupling a GUI

Mark Waes
Greenhorn

Joined: Aug 06, 2008
Posts: 21
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

Joined: Aug 31, 2004
Posts: 11343

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?


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Mark Waes
Greenhorn

Joined: Aug 06, 2008
Posts: 21
Thanks. I'll give it a go...
Mark Waes
Greenhorn

Joined: Aug 06, 2008
Posts: 21
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

Joined: Feb 23, 2007
Posts: 1561
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A Beginner's Guide to Decoupling a GUI
 
Similar Threads
Quadratic perplextion
More help on Java problem.
Passing two ints (hours and minutes and converting them to proper decimals) ?
Help with compiler error
Need help on passing values from one method to another