Animation is defined as a rapid(fast/quick) display of text or images. These images or text have to be created in a specific pattern. When they are displayed rapidly it causes an appearance of movement.
Example of animation in Applet
import javax. swing.*;
import java.awt.*;
public class animation1 extends JApplet implements Runnable
{
JLabel labelanimationn;
String job[]={“Sales Manager-0002″,”Marketing Manager-0003″,”Financial Analyst-0004″,”Database Analyst-0005”, “Consultant-00007”};
int counterr;
Thread animationthreadd;
public void init()
{
labelanimationn=new JLabel(” “); //empty label for animation
Container contentt=getContentPane();
JPanel panell=new JPanel();
panell.setLayout(new FlowLayout());
panell.add(labelanimationn);
panell.setBackground(Color.blue);
contentt.add(panell);
animationthreadd=new Thread(this);
animationthreadd.start();
}
public void run()
{
for(;;) //infinite loop for animation
{
displayvacancy(); //function calling
try
{
animationthreadd.sleep(1000);//wait for 1 second
showStatus(“Thread animation one by one “); //for status bar(message)
}
catch(InterruptedException ee)
{
showStatus(“Thread interupted”);
}
}
}
public void displayvacancy()
{
Font ff=new Font(“Times New Roman”,Font.BOLD,28); //jlabel font setting
labelanimationn.setFont(ff);
labelanimationn.setText(job[counterr]); //animation (job)set in label
counterr++;//one by one increment
if(counterr>=5)
{
counterr=0;
}
}
}
/*<applet code=”animation1.class” height=500 width=500></applet>*/
Explanation….
In the above example animation is displayed in a sequence. This sequence is called a looping sequence. The advantage of a looping sequence is that an animated display consisting of fewer images can run for a prolonged period. In the above example, we create a thread that runs in an infinite loop and displays the text sequence one at a time.