Solved

How to display an animated gif in an applet ?

Posted on 1997-12-10
6
394 Views
Last Modified: 2012-06-21
Hi,

I'd like to know how to display an animated GIF image in an applet window.

Thank tou for your help

Renaud
0
Comment
Question by:hilleret
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 1

Expert Comment

by:pyramid
ID: 1231554
Hi;

I am assuming that you have a number of gif files that together create the appearance of movement. Let's say you have 10 separate gif files named file1.gif through file10.gif. You have to create an array that the program can access and run the gifs in  an applet. There is alot of code to understand and I tried to explain it in this small space, hope it helps you

regards....

Pyramid

here is some sample code;

//import all your awt libraries
import java.awt.*

//create a class that implements the runnable extention

public class [class name here] extends java.applet.Applet implement runnable {
//create your array
//you have 10 files, an array uses numbers 0 through 9
Image filepics[ ]=new Image[9];
//sets a variable for the image to reside in
Image currentimg;
//need a thread variable for the image to start and stop
Thread runner;
//I believe setting a position is optional
int xpos=#;
int ypos=#;
//initialize the array
public void init( ) {
//get the gif files
String filesrc[ ] = {"file1.gif",file2.gif".......file10.gif}
//interate the files located in a image directory or any location //you like
for (int=0; i<filepics.length; i++) {
filepics[1] = getImage(getCodeBase(), "images/" + filesrc[i]);
    }

}

//this is a must and is exactly the code you need here

public void start( ) {
if (runner==null) {
runner=new Thread(this);
runner.start( );
  }
}
public void stop( ) {
if (runner !=null) {
runner.stop( );
runner = null;
  }
}

//this section will run the files for you

public void run( ) {
//write this out for the number of files you have and advance //the array[1] through [10]
currentimg = filepics[1];
repaint( );
//this pause is in second 1000 is one second and can be //adjusted
pause(1000);

//this is a must have for parsing time intervals

void pause(int time) {
try {Thread.sleep(time); }
catch (InterruptedException e) { }
}
//paint to the template
public void paint(Graphics g) {
g.drawImage(currentimg, xpos, ypos, this);

   }
}
0
 
LVL 2

Author Comment

by:hilleret
ID: 1231555
Thank you for your answer, and

SORRY because I do not have separate files !

I have a GIF file that, when opended in a browser, automatically displays an animation.

For example : http://www.micronet.fr/~hilleret/alert.gif

Thank you for your help

Renaud
0
 
LVL 4

Expert Comment

by:russgold
ID: 1231556
Animated GIFs do not run automatically under Java; however, it turns out that every time you repaint an animated GIF, it will display the next frame, so you can control the animation rate by delegating a thread to repaint it continually at the desired rate.

We have gotten this to work in the AppletViewer on Windows NT.  I don't know if it is portable.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:hilleret
ID: 1231557
Could you give me a sample coding of your solution ?

Renaud


0
 
LVL 5

Expert Comment

by:fontaine
ID: 1231558
Renaud, russgold's answer was OK. You were not obliged to reject his answer to continue the discussion. Even if he doesn't want to share his code, I thinck he can repost his answer...
0
 
LVL 4

Accepted Solution

by:
russgold earned 50 total points
ID: 1231559
reposting:
Animated GIFs do not run automatically under Java; however, it turns out that every time you repaint an animated GIF, it will display the next frame, so you can control the animation rate by delegating a thread to repaint it continually at the desired rate.

We have gotten this to work in the AppletViewer on Windows NT. I don't know if it is portable.

I don't know if I have any code that I can share (it's part of a proprietary system), but I will look.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question