FileDocCategorySizeDatePackage
CharacterEventHandler.javaAPI DocExample884Sat Apr 17 23:31:04 BST 2004javathreads.examples.ch08.example3

CharacterEventHandler

public class CharacterEventHandler extends Object

Fields Summary
private ArrayList
listeners
Constructors Summary
Methods Summary
public voidaddCharacterListener(CharacterListener cl)


        
        synchronized(listeners) {
            listeners.add(cl);
        }
    
public voidfireNewCharacter(CharacterSource source, int c)

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

        synchronized(listeners) {
            listeners.remove(cl);
        }