有利用過進度條的朋友必然會感覺很不利便
因為要從0~100讀取 浪費時候
因檔案巨細也不知道這時候間讀寫的完嗎?
如這篇
Java Swing 若何使用進度
於是顛末批改
改成此方式
可利用DIALOG準確的抓到讀寫完成的時候
- processdialog.setTitle("Copying files to USB");
- processdialog.add(labelimg);網站架設
- processdialog.setLocation(400,250);
- processdialog.pack(); // Packs the dialog so that the JOptionPane can be seen
- processdialog.setVisible(true); // Shows the dialog
- new Thread(){
- public void run(){
- try{
- Process process = null;
- BufferedReader input = null;
- final Runtime runtime = Runtime.getRuntime();
- //extact tar for ext3 file
- String tarstring = "tar -xvpf /"+tarpath+"/"+cellValue+".tar -C "+extpatition+"/";
- process = runtime.exec(new String[]{"/bin/sh","-c",tarstring});
- InputStream stdout = process.getInputStream ();
- InputStreamReader osr = new InputStreamReader (stdout);
- BufferedReader obr = new BufferedReader (osr);網站架設
- process.waitFor();
-
- Thread.sleep(2000);
- }catch(Exception e){
- e.printStackTrace();
- }finally{
- processdialog.dispose();
- }
- }
- }.start();網站架設
複製代碼
網站架設用new Thread如許包起來就能夠了
問甚麼要如許做呢?
因為dialog實際上是非常浪擲資本的
假如我程式起始啟動dialog
竣事用dialog.dispose();時
dialog圖標底子還沒出來就封閉了
就卡個視窗而以
完整過程圖片
以下內文出自:
文章定位: