The Artima Developer Community
Sponsored Link

Java Answers Forum
Animated gifs get slower... and slower.........

0 replies.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a flat view of this topic  Flat View
Previous Topic   Next Topic
Threaded View: This topic has 0 replies on 1 page
Kelly Kopekny

Posts: 1
Nickname: radario
Registered: Sep, 2002

Animated gifs get slower... and slower......... Posted: Sep 26, 2002 1:23 PM
Reply to this message Reply
I have subclassed a JPanel to draw animated gifs on, like an image viewer kind of thing. As I redraw different gifs on the panel, they begin to display slower and slower to the point where I have to close the program. How can I prevent this from happening?

class ImagePanel extends JPanel {
Toolkit tk = Toolkit.getDefaultToolkit();
Font f = new Font("Ariel",Font.ITALIC, 24);
JPanel draw = new JPanel(true);


//Constructor
public ImagePanel() {

setContentPane(draw);


setBackground(Color.black);
setForeground(Color.white);

}
//Repaint Method
public void PaintImage(String file) {

try {

img = tk.getImage(file);
mediaTracker = new MediaTracker(this);

mediaTracker.addImage(img, 0);
mediaTracker.waitForID(0);

} catch (InterruptedException e) {
System.out.println("InterruptedException has occurred:"
+ e.getMessage());

return;
}

x1 = img.getWidth(this);
y1 = img.getHeight(this);
x1 = x1/resize;
y1 = y1/resize;



repaint();
}


public void paintComponent(Graphics g) {

int y;
int cl;
super.paintComponent(g);

//~~~~~~~~~~~~~~~This is where we draw the Image
if (img != null) {


g.drawImage(img,0,0,x1,y1,this);
g.dispose();

}


}


Topic: Require a file-bean that will give me the path. Previous Topic   Next Topic Topic: Need some help. How do I tackle this?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use