为什么在我下载过程中我的JFrame是空白的?

时间:2012-09-10 08:33:48

标签: java jframe

我有一个extends JFrame的课程,里面有一个方法如下:

public void downloadUrl(String filename, String urlString) throws MalformedURLException, IOException
{
    BufferedInputStream in = null;
    FileOutputStream fout = null;
    try
    {
        in = new BufferedInputStream(new URL(urlString).openStream());
        fout = new FileOutputStream(filename);

        byte data[] = new byte[1024];
        int count;
        int modPackSize = getModPackSize();
        while ((count = in.read(data, 0, 1024)) != -1)
        {
            fout.write(data, 0, count);
            downloadedPerc += (count*1.0/modPackSize)*100;
            progressBar.setValue((int) downloadedPerc);
            label.setText((int) downloadedPerc + "%");
            System.out.println(downloadedPerc);
        }

    } catch (NoSuchAlgorithmException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    finally
    {           
        if (in != null)
            in.close();
        if (fout != null)
            fout.flush();   
        fout.close();
    }
}

此方法下载文件并获取下载的百分比。在运行时,我的JFrame是空白的。运行后,JFrame会更新并正确显示,但我希望它能够更新(好吧,首先显示自己),我怎么能这样做?

0 个答案:

没有答案