Hin Yee
Hin Yee

Reputation: 11

How to make a gif stop without click anything in JFrame?

The gif plays after entering the frame but how to make it stop automatically after it finished playing once (something like a video) ? I want it to stop at the last frame of the gif not completely close the frame after it has been played.

Upvotes: 0

Views: 172

Answers (1)

UmaShankar Chaurasiya
UmaShankar Chaurasiya

Reputation: 111

use JFrame.EXIT_ON_CLOSE

        URL img = this.getClass().getResource("src/image.gif");
        Icon icon = new ImageIcon(img);
        JLabel gif = new JLabel(icon);
        JFrame frame = new JFrame("gif");
        frame.getContentPane().add(label);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Upvotes: 1

Related Questions