FileDocCategorySizeDatePackage
AnimatedCharacterDisplayCanvas.javaAPI DocExample1271Sun Mar 14 11:44:38 GMT 2004javathreads.examples.ch11.example2

AnimatedCharacterDisplayCanvas

public class AnimatedCharacterDisplayCanvas extends CharacterDisplayCanvas implements ActionListener, CharacterListener

Fields Summary
private int
curX
private Timer
timer
Constructors Summary
public AnimatedCharacterDisplayCanvas(CharacterSource cs)

        super(cs);
	timer = new Timer(100, this);
    
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent ae)

        repaint();
    
public synchronized voidnewCharacter(CharacterEvent ce)

        curX = 0;
        tmpChar[0] = (char) ce.character;
        repaint();
    
public synchronized voidpaintComponent(java.awt.Graphics gc)

        if (tmpChar[0] == 0)
            return;
        Dimension d = getSize();
        int charWidth = fm.charWidth(tmpChar[0]);
        gc.clearRect(0, 0, d.width, d.height);
        gc.drawChars(tmpChar, 0, 1, curX++, fontHeight);
        if (curX > d.width - charWidth)
            curX = 0;
    
public voidsetDone(boolean b)

        if (!b)
           timer.start();
        else timer.stop();