Java设计模式——事件驱动模式(观察者模式)
角色
事件
事件源
事件监听器
事件
事件类一般继承自java.util.EventObject类,封装了事件源以及跟事件有关的信息
source:事件源
getSource():获取事件源
public class EventObject implements java.io.Serializable {
private static final long serialVersionUID = 5516075349620653480L;
/**
* The object on which the Event initially occurred
*/
protected transient Object source;
/**
* Constructs a prototypical Event.
*
* @param source The object on which the Event initially occurred.
* @exception IllegalArgumentException if source is null.
*/
public EventObject(Object source) {
if (source == null)
throw new IllegalArgumentException("null source");
this.source = source;
}
/**
* The object