|
|
Animated gifs get slower... and slower.........
|
Posted: Sep 26, 2002 1:23 PM
|
|
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(); }
}
|
|