W
wunglee
Unregistered / Unconfirmed
GUEST, unregistred user!
/********************
/*file: FooEvent.java
/********************
package EventInterface;
public interface FooListener extends java.util.EventListener{
public void handleFooEvent(FooEvent evt);
}
/********************
/*file: FooEventGenerator.java
/********************
package EventSource;
import EventInterface.FooListener;
public class FooEventGenerator{
public void addFooListener(FooListener l){
//Code to add listener to the list of listeners.
}
public void removeFooListener(FooListener l){
// Code to remove listener from the list of listeners.
}
private void notifyFooListeners(){ //进入notifyFooListeners()的进入点在哪里?
//也就是事件发生后由什么来调用notifyFooListeners()?
//它怎么知道该调用的是notifyFooListeners()方法?
// Create a FooEvent with this as the source.
FooEvent fooEvent = new FooEvent(this);
// Deliver the event. //是不是事件源通过显式调用监听接口的方法来派发该事件?
}
}
/********************
/*file: FooEventGenerator.java
/********************
import EventInterface.FooListener
import EventSource.FooEventGenerator
public class FooTest implements FooListener{
// Implement the FooListener interface.
public void handleFooEvent(FooEvent evt){
System.out.println("Received FooEvent!");
}
}
FooEventGenerator eventSource = new FooEventGenerator();
FooTest listener = new FooTest();
eventSource.addFooListener(listener);
/*file: FooEvent.java
/********************
package EventInterface;
public interface FooListener extends java.util.EventListener{
public void handleFooEvent(FooEvent evt);
}
/********************
/*file: FooEventGenerator.java
/********************
package EventSource;
import EventInterface.FooListener;
public class FooEventGenerator{
public void addFooListener(FooListener l){
//Code to add listener to the list of listeners.
}
public void removeFooListener(FooListener l){
// Code to remove listener from the list of listeners.
}
private void notifyFooListeners(){ //进入notifyFooListeners()的进入点在哪里?
//也就是事件发生后由什么来调用notifyFooListeners()?
//它怎么知道该调用的是notifyFooListeners()方法?
// Create a FooEvent with this as the source.
FooEvent fooEvent = new FooEvent(this);
// Deliver the event. //是不是事件源通过显式调用监听接口的方法来派发该事件?
}
}
/********************
/*file: FooEventGenerator.java
/********************
import EventInterface.FooListener
import EventSource.FooEventGenerator
public class FooTest implements FooListener{
// Implement the FooListener interface.
public void handleFooEvent(FooEvent evt){
System.out.println("Received FooEvent!");
}
}
FooEventGenerator eventSource = new FooEventGenerator();
FooTest listener = new FooTest();
eventSource.addFooListener(listener);