Generic Event/Listener implementation.
USAGE:
class Worker implements Runnable {
private final EventMulticaster updateObserver;
private void doWork() {
if (stateChanged()) updateObserver.fireUpdateEvent();
...
public void addWorkEventListener(UpdateEventListener listener) {
updateObserver.addListener(listener);
...
class Master {
private void delegateTask() {
Worker worker = new Worker();
worker.addWorkEventListener(new UpdateEventListener() {
public void handleUpdate(Object data) {
System.out.println(data);
}
});
...
|