Animation in Java Applets
Java Programming

Animation in Java Applets

 

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>*/

Animation in Java 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.

Recommended Posts

C++ Programming

Visibility modes in C++

In C++, visibility modes refer to the accessibility of class members (such as variables and functions) from different parts of a program. C++ provides three visibility modes: public, private, and protected. These modes control the access levels of class members concerning the outside world and derived classes. Public: Members declared as public are accessible from […]

Rekha Setia 
C++ Programming

Inheritance in C++

In C++, inheritance is a fundamental concept of object-oriented programming (OOP) that allows you to create a new class based on an existing class, known as the base or parent class. The new class is called the derived or child class. Inheritance facilitates code reuse and supports the creation of a hierarchy of classes. There […]

Rekha Setia 
C++ Programming

C++ Classes and Objects

In C++, classes and objects are fundamental concepts that support object-oriented programming (OOP). Here’s a brief overview of classes and objects in C++: Classes: In C++, a class is a user-defined data type that allows you to encapsulate data members and member functions into a single unit. Classes are the building blocks of object-oriented programming […]

Rekha Setia 

Leave A Comment