Home Tutorial Java Thread Animation in Java Applet


Share on Google+Share on Google+
Animation in Java Applet
Posted on: November 9, 2009 at 12:00 AM
In this segment of tutorial we will learn about the Animation in Java applet. Then We will create an applet and use the animation it.

  • Applet is a java class that runs inside the internet browser.
  • It uses Thread along with its methods for animation.
  • Applet class implements the Runnable interface for animation program.

Example of Animation in Java program
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;

//<applet code="rect1" width="300" height="160"></applet>
public class rect1 extends Applet implements Runnable {
Thread t1;

public void init() {
t1 = new Thread(this);

public void start() {

public void run() {
Thread t2 = Thread.currentThread();
while (t1 == t2) {

public void paint(Graphics g) {
Color c[] = { Color.red, Color.yellow, Color.BLUE, Color.pink,
Color.MAGENTA };

for (int x = 0; x <= 4; x++) {
try {
g.fillRect(10, 10, 200, 200);
} catch (Exception e) {

public void stop() {
t1 = null;


Related Tags for Animation in Java Applet:

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 9, 2009

Recommend the tutorial

Advertisements Advertisements