O'Reilly logo

Java™ Drawing with Apache Batik: A Tutorial by Alexander Kolesnikov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding Animation

In this section we add animation to SVG Interactor. For each type of animation, we create a Java class that implements java.lang.Runnable. For instance, the CircleMovement class below is the class responsible for the movement of a circle.

public class CircleMovement implements Runnable {
    private int deltaY = 1;
    public void run() {
        Element elt = document.getElementById("theCircle");
        int yPos = Integer.parseInt(elt.getAttribute("cy"));
        if ((yPos <= 70) || (yPos >= 330)) {
            deltaY = -deltaY;
        }
        yPos += deltaY;
        elt.setAttribute("cy", "" + yPos);
    }
}

To perform the animation, we call the setInterval method of the window object, passing to it the appropriate Runnable object. This method should be called right after the element to animate ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required