
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class AnimateJFrameIconImage extends JFrame
{
Timer t;
int i;
    public AnimateJFrameIconImage()
    {
        createAndShowGUI();
    }
    
    private void createAndShowGUI()
    {
        setTitle("Animated Icon Image");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setLayout(new FlowLayout());
        
        // Create a Timer to do animation
        t=new Timer(10,new ActionListener(){
            public void actionPerformed(ActionEvent ae)
            {
                // Set icon image for JFrame
                setIconImage(new ImageIcon(getClass().getResource("/icons/busy-icon"+i+".png")).getImage());
                i++;
                // I have only 10 icons!
                if(i==10) i=0;
            }
        });
        
        t.start();
        
        setSize(400,400);
        setVisible(true);
    }
    
    public static void main(String args[])
    {
        new AnimateJFrameIconImage();
    }
}
The greatest compliment you can give me is when you share this with others. I sincerely appreciate it :)
 
No comments:
Post a Comment