📜  Java.util.Observable类

📅  最后修改于: 2020-11-14 06:20:21             🧑  作者: Mango


介绍

java.util.Observable类表示可观察对象,即模型视图范例中的“数据”。以下是有关Observable的要点-

  • 该类可以被子类化以表示应用程序希望观察到的对象。

  • 一个可观察对象可以具有一个或多个观察者。

类声明

以下是java.util.Observable类的声明-

public class Observable
   extends Object

类的构造函数

Sr.No. Constructor & Description
1

Observable()

This constructs an Observable with zero Observers.

类方法

Sr.No. Method & Description
1 void addObserver(Observer o)

This method adds an observer to the set of observers for this object, provided that it is not the same as some observer already in the set.

2 protected void clearChanged()

This method indicates that this object has no longer changed, or that it has already notified all of its observers of its most recent change, so that the hasChanged method will now return false.

3 int countObservers()

This method returns the number of observers of this Observable object.

4 void deleteObserver(Observer o)

This method deletes an observer from the set of observers of this object.

5 void deleteObservers()

This method clears the observer list so that this object no longer has any observers.

6 boolean hasChanged()

This method tests if this object has changed.

7 void notifyObservers()

If this object has changed, as indicated by the hasChanged method, then notify all of its observers and then call the clearChanged method to indicate that this object has no longer changed.

8 void notifyObservers(Object arg)

If this object has changed, as indicated by the hasChanged method, then notify all of its observers and then call the clearChanged method to indicate that this object has no longer changed.

9 protected void setChanged()

This method returns marks this Observable object as having been changed; the hasChanged method will now return true.

方法继承

此类从以下类继承方法-

  • java.util.Object