package com.gyarmy.testPerson;
public class Person {
public void eat()
{
Event e = new Event(this);
pl.doEat(e);
System.out.println("吃......");
}
public void run()
{
Event e = new Event(this);
pl.doRun(e);
System.out.println("跑......");
}
private PersonListener pl;
public void addPersonListener(PersonListener pl)
{
this.pl = pl;
}
}
//事件监听器接口
interface PersonListener{
public void doEat(Event e);
public void doRun(Event e);
}
//事件对象 --- 封装 事件源
class Event{
private Person p;
public Event(Person p){
this.p = p;
}
public Person getP()
{
return p;
}
}