JProgressBar 主要方法: progressBar = new JProgressBar(); ...//when the task of (initially) unknown length begins: progressBar.setIndeterminate(true); ...//do some work; get length of task... progressBar.setMaximum(newLength); progressBar.setValue(newValue); progressBar.setIndeterminate(false);sun example http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html简单点网上找个gif图片 执行操作的时候弹出来就OK了
主要方法:
progressBar = new JProgressBar();
...//when the task of (initially) unknown length begins:
progressBar.setIndeterminate(true);
...//do some work; get length of task...
progressBar.setMaximum(newLength);
progressBar.setValue(newValue);
progressBar.setIndeterminate(false);sun example
http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html简单点网上找个gif图片 执行操作的时候弹出来就OK了
public void run(){
FileInputStream fis=null;
FileOutputStream fos=null;
try {
fis=new FileInputStream(sourceText.getText());
fos=new FileOutputStream(newText.getText());
bar.setMaximum((int)l);
while(fis.available()>0){
fos.write(fis.read()^Integer.parseInt(text.getText()));//文件加密
bar.setValue(i++);
try {
Thread.sleep(10);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
JOptionPane.showMessageDialog(frame, "文件加密/解密成功!");
clear();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}finally{
try {
if(fis!=null){ fis.close();}
if(fos!=null){fos.close();}
} catch (IOException ex) {}
}
}
};
t.start();
LZ可以看看bar.setValue(i++);使滚动条自动增加的,滚动条总的长度是由文件大小来决定的,希望对lz有参考价值