well, this was my test code:
Code:
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.beans.PropertyChangeEvent;
import javax.swing.event.SwingPropertyChangeSupport;
class test
{
PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
int x = 50;
long y = 0;
public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener){
if(listener == null){
return;
}
if (changeSupport == null){
changeSupport = new PropertyChangeSupport(this);
}
changeSupport.addPropertyChangeListener(propertyName, listener);
}
public void firePropertyChange(String name, int oldVal, int newVal){
if ((changeSupport != null) && (oldVal != newVal)) {
changeSupport.firePropertyChange(name, new Integer(oldVal), new Integer(newVal));
}
}
public void setX(int x){
if(this.x == x){
System.out.println("not changed.");
return;
}
int oldx = this.x;
this.x = x;
changeSupport.firePropertyChange("x", oldx, x);
System.out.println(x);
}
public static void main(String[] s){
test t = new test();
t.setX(50);
}
public test(){
this.addPropertyChangeListener("x", new PropertyChangeListener(){ public void propertyChange(PropertyChangeEvent pce){ System.out.println("i was changed"); }});
}
}
i basically looked through the source of JComponent, Container, etc, for how to do it in the java.src zip file
but upon realizing how its done, im not so sure if i need it anymore, because it really is only uesd to notify other objects of the its' states' changing, not itself, or something, and that is what that test prog is doing, but it may be useful.