A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Android Security Essentials Live Lessons
this week in the
Swing / AWT / SWT
Question Regarding MVC Approach
Joined: Nov 11, 2004
Apr 28, 2005 05:35:00
I'm looking primarily for non-technical replies it's more an opinion based post.
I have implemented the following approach:
// MVC Approach //
Class Model (observable)- holds the collection storing my data. Sets class GUI as an observer.
Class GUI (observer) - displays a table displaying the collection data
When changes are made in the model it uses the following code to alert its observers - setChanged() & notifyObservers().
The GUI implements the update method which is ran when notifyObservers is called, in the update method I call updates on the table to make it refresh.
Is this the correct way to implement MVC? I have heard rumors that my table should be directly observing the model and shouldn't need to call the repaint method.
I'm starting to get confused again so any advice appreciated.
Joined: Jul 11, 2001
Apr 29, 2005 07:47:00
Speaking specifically about
You should create a TableModel and give this model to your
. Then you can modify the data in the table model which will notify the table when changes are made.
I think you are just overthinking it a bit.
Your design would be good for components that don't really have a model and still need to be updated in some way (JTextFields, JLabels, etc).
GenRocket - Experts at Building Test Data
Joined: Apr 05, 2005
Apr 29, 2005 10:24:00
If your model is used elsewhere in the system, you could also write an adapter that implements table model and uses your model for the actual data storage. Otherwise, I'm with Greg that just using tablemodel would be best.
I agree. Here's the link:
subject: Question Regarding MVC Approach
designing for multiple layers
Design Pattern for GUI implementation
Adding an action listener to an entire class
update() method problem in Observer interface
FBNX: Gui and Threads, asynchronous Swing action execution and GUI updating.
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014