集册 Java实例教程 实施绑定属性

实施绑定属性

欢马劈雪     最近更新时间:2020-01-02 10:19:05

410
实施绑定属性

import java.beans.PropertyChangeListener;
/**
来 自 nowjava.com - 时  代  Java
**/

import java.beans.PropertyChangeSupport;


public class Main {

  int myProperty;


  public int getMyProperty() {

    return myProperty;

  }


  public void setMyProperty(int newValue) {

    int oldValue = myProperty;

    myProperty = newValue;

    pceListeners.firePropertyChange("myProperty", new Integer(oldValue),

        new Integer(newValue));

  }


  // Create the listener list.

  PropertyChangeSupport pceListeners = new PropertyChangeSupport(this);


  // The listener list wrapper methods./**N o w J a v a . c o m - 时  代  Java**/

  public synchronized void addPropertyChangeListener(

      PropertyChangeListener listener) {

    pceListeners.addPropertyChangeListener(listener);

  }
展开阅读全文