JFrame GIF图像线程在重载期间挂起

时间:2017-08-09 20:02:24

标签: java multithreading jframe executor

尝试在繁重的Java加载过程中显示进度条。 Gif图像在单独运行时加载正常,但有2个线程并行运行,只有帧出现且没有Gif图像。

package com.manas.progress;

import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;


    public class ImagePanel extends JPanel implements Runnable{


        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
         public void run() {
            // TODO Auto-generated method stub
              URL url = null;
            try {
                url = new URL("File:\\progress_bar.gif");
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
                Icon icon = new ImageIcon(url);
                JLabel label = new JLabel(icon);

                JFrame f = new JFrame("Animation");
                f.getContentPane().add(label);
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                f.pack();
                f.setLocationRelativeTo(null);
                f.setVisible(true);
        }
      }

通话方式:

public void create(String json,String userName, String password, String filePath) throws ParserConfigurationException, SAXException, IOException {
    String auth = userName +":"+password;
    byte[] encodedBytes = Base64.encodeBase64(auth.getBytes());
    ImagePanel p1 = new ImagePanel();
    Thread thread = new Thread(p1);
    thread.run();   
        httpPost(json, new String(encodedBytes));
      }

0 个答案:

没有答案