Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Painting an Animated GIF

Status
Not open for further replies.

ronnyjljr

IS-IT--Management
Nov 23, 2003
249
US
Ok here goes,

I am using a customized list model, this list model uses a customized cell renderer. The object the cell renderer uses is a subclass of a JPanel.

I have an animated gif that I wanted to show, I am able to have the regular gif drawn but not the animated. Any help?

mBuddyIcon is defined as an ImageIcon, is this why it's not animating? I have also defined it as type Image before but the ImageIcon and Image types produce the same image, which is not animated. How do I get this to animate?

BackBuffer and BackDC are for the double buffering.

Code:
[blue]
	public void paint(Graphics g)
	{
		BackBuffer = createImage (this.getSize().width, this.getSize().height);
		BackDC = BackBuffer.getGraphics ();
		
		int NumOfImgs = (this.getWidth()/mRed.getWidth(null))+1; //RoundUp

		for(int i=0;i<NumOfImgs;i++)
		{
			BackDC.drawImage(mDefault,i*65,0,Color.BLACK,null);	
		}
		
		BackDC.setFont(listFont);
		BackDC.setColor(Color.WHITE);
		BackDC.drawString(mName,60,20);

		[red]mBuddyIcon.paintIcon(this,BackDC,0,0);
[green]//I have tried this and the following...[/green]
BackDC.drawImage(mBuddyIcon,0,0,Color.BLACK,null) [/red]
[green]//The latter of the two was using an Image and not an image icon[/green]

		g.drawImage(BackBuffer,0,0,this);

	}




[/blue]

Thanks,
Ron

typedef map<GiantX,gold, less<std::shortestpathtogold> > AwesomeMap;
 
An ImageIcon will handle an animated gif alright.

On ImageIcon there's a method called setImageObserver(). The ImageObserver is what triggers the animation. Here's the example in ImageIcon's source:
* icon = new ImageIcon(...)
* button.setIcon(icon);
* icon.setImageObserver(button);

Without the ImageObserver set, paintIcon() just paints the first frame to the component.

Hope this helps.
 
This paint method is inside the cell renderer object.
Is my image observer the Jlist that these objects are stored in? Or is it my custom object?

I would do this?

Code:
[red]
mBuddyIcon.paintIcon(this,BackDC,0,0);
mBuddyIcon.setImageObserver(this???);
mBuddyIcon.setImageObserver(myJlist??);

[/red]

Thanks,
Ron

typedef map<GiantX,gold, less<std::shortestpathtogold> > AwesomeMap;
 
Figured this out.

This image observer does need to be the Jlist. It works great!

Thanks,
Ron

typedef map<GiantX,gold, less<std::shortestpathtogold> > AwesomeMap;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top