I have a custom component that extends a JComponent. When you click it, it catches the event with a MouseListener. Depending on the state of the component and where you click, the data stored in it updates.
How can I notify the parent container when this happens while keeping it completely self-contained?
Myself, I would use the PropertyChangeSupport that comes with JComponent, and then fire your notify method whenever the program’s state changes.
For example:
Regarding comments:
A ChangeListener will work fine too. 1+ to user129… but what I like about PCL is that I can specify the names of properties to listen for allowing me to listen to the changes of multiple different states and this way can create a complete View from a MVC design that is completely decoupled from the Control. So my recommendation is: if you’re only listening to one state, then by all means use a ChangeListener, but if you’re listening to multiple states, use a PCL.