Re: MVC and application state
Philipp wrote:
On the other hand, if for example the value is changed from somewhere
else in the code while the GUI is showing, the GUI will not be updated.
So you would have to implement some sort of ChangeListener equivalent,
is this correct?
While Eric gave great answers, I wanted point out that a ChangeListener
would only be appropriate if the value of the checkBox (or any other
intern GUI state) if the state can change while the GUI is displaying on
screen.
I would construct the GUI element (JFrame, Dialog, etc.) from the
application state (the boolean or whatever) only when I was about to use
that particular GUI element. Then I'd display it, and retrieve state
from the GUI object when the GUI is done. I'd probably call dispose()
on the element too, just to release resources, and dispose the object.
If you GUI element is persistent (i.e., it's the main application
top-window) and always displayed then yes, you'll need a ChangeListener
(or whatever interface you decide is best) to update that state so the
user can see it. But normally I associate checkBoxes with Dialog Boxes
and simple user interactions that don't need to watch for an external state.