Trying to show a progress bar during heavy Java loading. Gif image loads fine when it is run separately but with 2 threads running in parallel, only the frame comes up and no Gif image.
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);
}
}
Calling Method:
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));
}