import java.awt.*;

    // Continuously animate a MovingArc.
    // Use double buffering to avoid flicker.
class DoubleBufferCanvas extends Canvas {
        // Perform the next animation step.
        // Render the image of the arc in the offscreen graphics context.
    public void step(){
        // Move the arc on.
        getArc().step();
        // Draw the current arc in the offscreen image.
        drawOffscreenImage();
        // Paint it to the onscreen one.
        paint(getGraphics());
    }

    public void paint(Graphics g){
        // Copy the offscreen image to this component's context.
        g.drawImage(getImage(),0,0,this);
    }

        // Draw the arc in its current position in the offscreen image.
    protected void drawOffscreenImage(){
        Dimension size = getSize();
        // Make sure we have a suitable offscreen image.
        Image offscreenImage = getImage();
        if((offscreenImage == null) ||
                   (offscreenImage.getWidth(this) != size.width) ||
                   (offscreenImage.getHeight(this) != size.height)){
            // Create a new one.
            offscreenImage = createImage(size.width,size.height);
            setImage(offscreenImage);
        }

        // Perform the drawing.
        final int x = size.width/4, y = size.height/4;
        final int width = size.width/2, height = size.height/2;
        MovingArc arc = getArc();
        final int startAngle = arc.getAngle();
        final int arcWidth = arc.getWidth();

        // Obtain the offscreen graphics context.
        Graphics g = getImage().getGraphics();

        // Clear the previous image.
        g.clearRect(0,0,size.width,size.height);

        // Draw this one.
        g.fillArc(x,y,width,height,startAngle,arcWidth);
    }

    protected MovingArc getArc(){
        return arc;
    }

    protected Image getImage(){
        return image;
    }

    protected void setImage(Image i){
        image = i;
    }

    // Move clockwise.
    private final int increment = -1;
    // The arc to be animated.
    private final MovingArc arc = new MovingArc(increment);
    // An image to provide an off-screen graphics context.
    private Image image = null;
}

