In the GUI I am creating, I need a class higher up in the class tree to know when a class variable has changed in a lower class. I was hoping to notify a change when a basic data type (eg: String or int) property of the class changed, but I am unsure whether that can be done by a property change listener attached to the class. In the first sentence of "How to Write a Property Change Listener" http://docs.oracle.com/javase/tutorial/uiswing/events/propertychangelistener.html it says:
Property-change events occur whenever the value of a bound property changes for a bean ??? a component that conforms to the JavaBeans™ specification.
Try as I might, I cannot find a list which describes components that conform to the JBeans spec. The tutorial goes on to say:
All Swing components are also beans.
But I was hoping that I could notify the parent class of a change in a basic data type variable. Can someone let me know if I am going about this correctly? Or suggest an alternate method that will achieve the same end? Thanks.
Here is a VERY basic example of what I am trying to attempt.
This should be printing out the changed values as described in the anonymous class attatched to the listener, yes?
PropertyChangeListener is for any JavaBean and is not really related to Swing. However, Swing components themselves provide good support for property change listeners and you can use them.
However, from your description, I think you are trying to listen for property changes in your own classes...in that case, PropertyChangeSupport will prove very handy for you.
And, you might want to checkout this tutorial page to know more about that.
SCJP 1.4, OCMJEA/SCEA 5.0.
Joined: Oct 26, 2012
Thank you SOOOO much! This was exactly what I was looking for. After asking 3 different times on 3 different topic threads, someone finally gave me the answer that I was asking for instead of the answer they thought I should have.