Source Code : Animation label

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Animation label

 
import java.awt.Graphics;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;

public class AnimatedLabel extends JLabel implements Runnable {
  protected Icon[] icons;

  protected int index = 0;

  protected boolean isRunning;

  public AnimatedLabel(String gifName, int numGifs) {
    icons = new Icon[numGifs];
    for (int i = 0; i < numGifs; i++)
      icons[i] = new ImageIcon(gifName + i + ".gif");
    setIcon(icons[0]);

    Thread tr = new Thread(this);
    tr.setPriority(Thread.MAX_PRIORITY);
    tr.start();
  }

  public void setRunning(boolean r) {
    isRunning = r;
  }

  public boolean getRunning() {
    return isRunning;
  }

  public void run() {
    while (true) {
      if (isRunning) {
        index++;
        if (index >= icons.length)
          index = 0;
        setIcon(icons[index]);
        Graphics g = getGraphics();
        icons[index].paintIcon(this, g, 0, 0);
      } else {
        if (index > 0) {
          index = 0;
          setIcon(icons[0]);
        }
      }
      try {
        Thread.sleep(500);
      } catch (Exception ex) {
      }
    }
  }
}


           
         
  

Thank with us