Animation With Java Swing
A while back I made some animation for a song using p5.js. I thought that it would be great to make another video but instead do it with Swing. This is doable with JFrame and JPanel. I also imported JLabel in order to display some lyrics of the song I was making animation for as well as Timer which is important for controlling frame rate.
Timer
One of the great challenges of making this video involved the usage of Timer. I found that the playback of the video was often inconsistent and one of the things I had to do to keep it from slowing down was to increase the Timer value.
The first parameter is the frame-rate speed. Whatever this number is is the frequency in milliseconds that it refreshes. So if this number is low, it will refresh very frequently. I tried it with 5ms and it ran about twice as slow during screen capture, so I needed to find a frame-rate that was less frequent to improve performance. 36ms came very close to what I needed it to do.
JFrame and JPanel
There are a number of tutorials out there for doing animations in Swing. Sometimes you will have a class extending either the JFrame or JPanel class depending on what you are trying to accomplish. Some of them have some decent information, however I highly recommend looking at the Oracle Docs. There is an excellent tutorial on…