Original address: http://yanwushu.sinaapp.com/?p=48
GIF is a common means of implementing animations in swing. The simplest way to typically display a picture in swing is to call the JButton or JLabel's SetIcon (icon icon) method. However, this is not a good way to display GIF images, because if you do this you will find that the GIF refresh rate is often very fast, or should be said too fast, and the corresponding CPU utilization will increase significantly, in severe cases may lead to panic.
In order to solve this problem you can choose the following two ideas, the first idea is: the GIF image into a number of static pictures, and then through the program cycle display these pictures, to achieve the purpose of animation. For example, this is certainly bad practice, cumbersome, and a lot of work.
Animating with looping display
The second idea is to use code to parse GIF files manually, this part of this article provides a complete implementation of the download link at the end of the article. The Gifanalysis.java in the download package is an analysis tool for GIF. Gif.java is a reference for rendering GIF.
If you want to understand the Gifanalysis.java implementation principle, then need to have some basic understanding of the GIF file format and understand the interface of Java processing GIF, then please refer to the link at the end, this is a translation, may be some not fluent, interested people can find the relevant foreign documents.
Principle of implementation: http://www.blogjava.net/javagui/archive/2008/12/07/javafx.html
Code Download: Http://pan.baidu.com/s/1kT40wPT
If the resource fails, please notify [email protected]il.com
Java Swing Display gif