In the overridden function for my JFrame
:
@Override
protected void paintComponent(Graphics g) {
BufferedImage imagePerson;
try {
imagePerson = ImageIO.read(new File("errol.gif"));
} catch (IOException e) {
imagePerson = null;
}
g.drawImage(imagePerson, i * increment, j * increment - 1, null);
}
How can I change this so the animation on the gif is shown (without using threading). I have spent many hours trying to get this to work but to no avail.
You could use an ImageIcon
for this purpose. Have a look here and here. If you need the animation on a JPanel
, simply add a JLabel
(with the ImageIcon
) to the panel.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With