FileDocCategorySizeDatePackage
CharacterEventHandler.javaAPI DocExample685Mon Apr 05 08:25:00 BST 2004javathreads.examples.ch03

CharacterEventHandler.java

package javathreads.examples.ch03;

import java.util.*;

public class CharacterEventHandler {
    private Vector listeners = new Vector();

    public void addCharacterListener(CharacterListener cl) {
        listeners.add(cl);
    }

    public void removeCharacterListener(CharacterListener cl) {
        listeners.remove(cl);
    }

    public void fireNewCharacter(CharacterSource source, int c) {
        CharacterEvent ce = new CharacterEvent(source, c);
        CharacterListener[] cl = (CharacterListener[] )
            listeners.toArray(new CharacterListener[0]);
        for (int i = 0; i < cl.length; i++)
            cl[i].newCharacter(ce);
    }
}