Using JavaScript I would highly recommend D3 (http://d3js.org).
It's very well documented and there are a lot of tutorials and examples available:
eg. https://github.com/mbostock/d3/wiki/Gallery
If you are especially interested in animations and transitions this link might be interesting: http://blog.visual.ly/creating-animations-and-transitions-with-d3-js
In java, you can draw and make move an simple object with Swing which is usually used for human–computer interactions. But, maybe I don't understand, you want to use it online, I mean, through a JAVA applet? Maybe HTML5 could be a better choice.
Even a simple animation can take too much lines for this text thread. I found this video explaining one short code : https://www.youtube.com/watch?v=I3usNR8JrEE. If you want to check which animation is made, go to the seventh minute. I think they use Eclipse.
One more thing, if you think to use it as an applet, be careful, the modern browsers block the execution more and more by defaut (check https://www.java.com/en/download/help/browser_activate_plugin.xml).