Hey,
I'm getting started with the MVC-Pattern right now and have something I'm pondering about. Imagine following case:
I've got a view (obviously). In this view the User can select a file and then click a "Load"-Button. As soon as this load-button is clicked, all other components in my gui should be enabled as they are set to "disabled" as long as no file has been loaded.
What I've done till now:
I have created a view according to the following scheme:
public class GUI implements Observer {
private JButton loadButton, showButton;
private JComboBox nameBox;
private Controller controller = new Controller();
// Initialising Component and so on...
loadButton.addActionListener(... // calls the loadFile()-Method
public void update(Observable arg0, Object arg1) {
// What to do here?
}
}
And a controller like this:
public class Controller extends Observable {
public void loadFile() {
// Load selected File
notifyObservers(); // <--- What should they be notified about in order to enable their component?
}
}
So my problem is that I am not sure whether it is sensible to enable the components over the controller. Or is it better to check in the view, if the file has been loaded and then set the components to enabled?