集册 Java实例教程 实施约束属性

实施约束属性

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

539
实施约束属性
/** 来 自 时   代    Java - nowjava.com**/


import java.beans.PropertyVetoException;

import java.beans.VetoableChangeListener;

import java.beans.VetoableChangeSupport;


public class Main {

  int myProperty;


  public int getMyProperty() {

    return myProperty;

  }


  // Create the listener list.//from n o w j a v a . c o m - 时  代  Java

  VetoableChangeSupport vceListeners = new VetoableChangeSupport(this);


  // The listener list wrapper methods.

  public synchronized void addVetoableChangeListener(

      VetoableChangeListener listener) {

    vceListeners.addVetoableChangeListener(listener);

  }


  public synchronized void removeVetoableChangeListener(

      VetoableChangeListener listener) {

    vceListeners.removeVetoableChangeListener(listener);

  }


  public void setMyProperty(int newValue) throws PropertyVetoException {

    try {

      vceListeners.fireVetoableChange(
展开阅读全文