|JSRs 184, 226, and 239: Graphics Capabilities > Scalable 2D Vector Graphics (JSR 226) > Running SVGDemo|
This application plays an SVG animation depicting a Halloween greeting card. Press 8 to play, 5 to start, and 0 to stop. If you press 8, pressing 5 resumes the animation. If you press 0, pressing 5 starts the animation from the beginning.
The SVG file contains a description of how the various image elements evolve over time to provide this short animation.
In the following code sample, the JSR 226 javax.microedition.m2g.SVGImage class is used to load the SVG resource. Then, the javax.microedition.m2g.SVGAnimator class can take all the complexity of SVG animations and provides a java.awt.Component or javax.swing.JComponent which plays the animation. The SVGAnimator class provides methods to play, pause and stop the animation.
import javax.microedition.m2g.ScalableGraphics; import javax.microedition.m2g.SVGImage; ... String svgURI = ...; SVGImage svgImage = (SVGImage) SVGImage.createImage(svgURI, null); SVGAnimator svgAnimator = SVGAnimator.createAnimator(svgImage); // If running a JSE applet, the target component is a JComponent. JComponent svgAnimationComponent = (JComponent) svgAnimator.getTargetComponent(); ... svgAnimator.play(); ... svgAnimator.pause(); ... svgAnimator.stop();