Show animated GIF

后端 未结 9 1753
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-27 05:38

How do you display an animated GIF in a Java application?

9条回答
  •  时光说笑
    2020-11-27 06:18

    //Class Name
    public class ClassName {
    //Make it runnable
    public static void main(String args[]) throws MalformedURLException{
    //Get the URL
    URL img = this.getClass().getResource("src/Name.gif");
    //Make it to a Icon
    Icon icon = new ImageIcon(img);
    //Make a new JLabel that shows "icon"
    JLabel Gif = new JLabel(icon);
    
    //Make a new Window
    JFrame main = new JFrame("gif");
    //adds the JLabel to the Window
    main.getContentPane().add(Gif);
    //Shows where and how big the Window is
    main.setBounds(x, y, H, W);
    //set the Default Close Operation to Exit everything on Close
    main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //Open the Window
    main.setVisible(true);
       }
    }
    

提交回复
热议问题