By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,782 Members | 1,154 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,782 IT Pros & Developers. It's quick & easy.

Animated GIF on Java Application On Linux system

P: n/a
JW
Hi,

I am trying to see if I can display an animated .gif file
on a Java application (that is, I do not want to have
to show a series of static images to simulate animateion;
I just want to display a file that is of the animated .gif
type).

I was able run the following code (2 java classes) on a Windows 2000 machine
using Java 1.4 and it works fine,
but on Redhat linux 7.3 (KDE desktop), I just get a blank panel, without
the image, and without error messages.

Has anyone been able to successfully do what I am trying to do
on a Redhat system (using Java 1.4)?

Thank you

---
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class AnimatedPanel extends JPanel
{

final String animatedPic = "animated.gif";
final String blankPic = "blank.gif";

private ImagePanel imagePanel;

private boolean animationStarted = false;
public AnimatedPanel()
{
imagePanel = new ImagePanel(animatedPic);
setLayout(new BorderLayout());
//add(imagePanel,"Center");
add(imagePanel);
}

public static void main(String[] args)
{

JFrame f2=new JFrame();
f2.setSize(500,500);
f2.setTitle("arc");
f2.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e)
{

}
});

AnimatedPanel an=new AnimatedPanel();

f2.getContentPane().add(an);
f2.show();
}
}
---
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

import java.io.File;

class ImagePanel extends JPanel
{
protected Image image;
protected int x=0;
protected int y=0;

private MediaTracker tracker;
public ImagePanel(String filename)
{
Toolkit toolkit=Toolkit.getDefaultToolkit();
File file=new File(filename);
if ( file.exists())
image=toolkit.getImage(filename);

try {

tracker = new MediaTracker(this);
tracker.addImage(image, 0);
tracker.waitForID(0);
} catch (Exception e) {}

repaint();
}
public void setImage(String filename)
{
tracker.removeImage(image);
Toolkit toolkit=Toolkit.getDefaultToolkit();
File file=new File(filename);
if ( file.exists())
image=toolkit.getImage(filename);

try {
tracker.addImage(image, 0);
tracker.waitForID(0);
} catch (Exception e) {}
}

public void paintComponent(Graphics g)
{
super.paintComponent(g); //paint background

if(image!=null)
{
try
{
if (tracker.statusID(0, false) == MediaTracker.COMPLETE)
g.drawImage(image, x, y, this);
}
catch(Exception e)
{
System.out.println("ImagePanel Error: Can not render image!");
}
}
}
}
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
jk********@yahoo.com (JW) wrote in message news:<36**************************@posting.google. com>...

Post it to the BugParade. If you don't, I will.
http://developer.java.sun.com/servle...ade/index.html
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.