Share on Google+Share on Google+

Animation in Java Applet

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.yellow, Color.BLUE,,
Color.MAGENTA };

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

public void stop() {
t1 = null;



Posted on: November 9, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.


Advertisement null