473,412 Members | 5,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Animated GIF on Java Application On Linux system

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
1 5807
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: tmb | last post by:
1 - Is Microsoft dotnet a Virtual Machine... like the Java Virtual Machine... that will run on any operating system? 2 - If so, does Microsoft give away the dotnet development system like Sun...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
7
by: Alex | last post by:
Hi all, I am trying to install a java stored procedure via the windows development centre. The linux box is running 8.1 FP4 as is the windoze platform. If I am on the linux box i can install...
5
by: TZESENG | last post by:
DECEMBER 13, 2005 . Editions: N. America | Europe | Asia | Edition Preference News Analysis By Steve Hamm Source: http://www.businessweek.com/technology/content/dec2005/tc20051213_042973.htm...
0
by: Tomek | last post by:
Welcome. I`m trying to prepere some project that shows how to use Corba technology i heterogenic systems.I`d like to create CORBA server with Borland Delphi (or C#.NET) and few client...
7
by: Lemune | last post by:
Hi.. I am developing an application that connect to database on the other side of the net. And each time i want to connect to database and run some sql command, i want my user to know that there...
27
by: Phil | last post by:
I thought it would be nice to display some animated GIFs on some of my forms. I put a PictureBox control on a form, and loaded my GIF file in. It animates, but not properly. It seems very jerky and...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.