How to make animation using swing and clojure?

I'm trying to animate a chess piece on a board. First I created a java.util.Timer object, which "scheduleAtFixedRate" TimerTask is implemented as a proxy function. Thus, I saved the fragment record for moving (moving around the figure) and when it fits (when the user moves the piece with the mouse), the TimerTask proxy function should be a check if the record is non-zero, the mobile function. The blending function only updates the x and y coordinates of the shape according to a pre-calculated vector. I put the clock-clock on the record-move, so when it changes, he must repaint the board (canvas). The drawing method checks to see if this record with the movement of the workpiece is not null.

The problem is that the animation is not displayed. A piece simply jumps into fate, without movement between them. There is some problem with the animation scheme. Is there a better way to do this?

+7
java clojure animation swing
source share
5 answers

Updates to Swing components must be performed in the event dispatch stream (EDT). Therefore, you should use the Swing timer, since any code executed when the timer fires will execute on the EDT.

All you have to do is set the location of the chess piece and it will be automatically redrawn automatically.

See the Swing tutorial on How to Use Timers for more information .

+2
source share

Swing doesn't do the animation automatically, no matter if you have a timer or not. If you want to animate the movement, you need to move the piece a certain distance at a time and redraw the canvas with each movement, so it gives the illusion, so to speak, of the movement.

+1
source share

you can use the Trident library: here

+1
source share

There is a demo version of Animator in JDK. It uses awt, but it should give you some ideas.

jdk1.6.0_20 \ demo \ applets \ Animator

0
source share

Another idea is to take a look at the processing visualization infrastructure at processing.org. It is a simple but powerful and well-documented programming language for animation and visualization. The API is very simple and has a very transparent Clojure shell named Rosado .

0
source share

All Articles