close

有利用過進度條的同夥一定會感覺很不方便
因為要從0~100讀取 浪擲時間網頁設計
因檔案巨細也不知道這時候間讀寫的完嗎?
如這篇網頁設計
Java Swing 若何使用進度

於是經由批改
改成此方式
可哄騙DIALOG準確的抓到讀寫完成的時候

  1. processdialog.setTitle("Copying files to USB");
  2.                             processdialog.add(labelimg);
  3.                             processdialog.setLocation(400,250);
  4.                             processdialog.pack(); // Packs the dialog so that the JOptionPane can be seen
  5.                             processdialog.setVisible(true); // Shows the dialog
  6.                             new Thread(){
  7.                                     public void run(){
  8.                                             try{
  9.                                                 Process process = null;
  10.                                                 BufferedReader input = null;
  11.                                                 final Runtime runtime = Runtime.getRuntime();
  12.                                                 //extact tar for ext3 file
  13.                                                 String tarstring = "tar -xvpf /"+tarpath+"/"+cellValue+".tar -C "+extpatition+"/";
  14.                                                 process = runtime.exec(new String[]{"/bin/sh","-c",tarstring});
  15.                                                 InputStream stdout = process.getInputStream ();
  16.                                                 InputStreamReader osr = new InputStreamReader (stdout);
  17.                                                 BufferedReader obr = new BufferedReader (osr);
  18.                                                 process.waitFor();
  19.                                                
  20.                                                 Thread.sleep(2000);
  21.                                             }catch(Exception e){
  22.                                                     e.printStackTrace();
  23.                                             }finally{
  24.                                                     processdialog.dispose();
  25.                                             }
  26.                                     }
  27.                             }.start();
複製代碼

new Thread如許包起來就能夠了
問甚麼要如許做呢?
因為dialog其實是非常鋪張資本的
假如我程式肇端啟動dialog
竣事用dialog.dispose();時
dialog圖標底子還沒出來就封閉了
就卡個視窗而以
完全進程圖片

網頁設計1.png



文章來自:
arrow
arrow
    文章標籤
    網頁設計
    全站熱搜

    aupfttyyrvt 發表在 痞客邦 留言(0) 人氣()