所以我试图做一个下载器,用进度条显示下载进度。但是我遇到了问题,因为它实际上没有更新进度条。当它本来是蓝色时,基本上保持白色。如果有人可以帮助,则下面的代码。
JProgressBar progressBar = new JProgressBar(0, ia);
con.add(progressBar, BorderLayout.PAGE_START);
con.validate();
con.repaint();
progressBar = new JProgressBar(0, ia);
progressBar.setValue(0);
System.out.print("Downloading Files");
while ((count = in.read(data, 0, downloadSpeed)) != -1){
fout.write(data, 0, count);
if (count >= 2){
progressBar.setString("Downloading : " + ia + " @ " + count + "Kbs per second");
} else {
progressBar.setString("Downloading : " + ia + " @ " + count + "Kb per second");
}
progressBar.setValue(count);
con.add(progressBar, BorderLayout.PAGE_START);
try{
Thread.sleep(1000);
} catch (Exception e){}
}
一只萌萌小番薯
牧羊人nacy
相关分类