zoukankan      html  css  js  c++  java
  • 转:ProgressMonitorDialog

    http://stackoverflow.com/questions/12986912/using-progressmonitordialog-in-eclipse-4-properly

     1 public class Progress {
     2     public static void main(String[] args)
     3     {
     4         // Create your new ProgressMonitorDialog with a IRunnableWithProgress
     5         try {
     6             // 10 is the workload, so in your case the number of files to copy
     7             IRunnableWithProgress op = new YourThread(10);
     8             new ProgressMonitorDialog(new Shell()).run(true, true, op);
     9          } catch (InvocationTargetException ex) {
    10              ex.printStackTrace();
    11          } catch (InterruptedException ex) {
    12              ex.printStackTrace();
    13          }
    14     }
    15 
    16     private static class YourThread implements IRunnableWithProgress
    17     {
    18         private int workload;
    19 
    20         public YourThread(int workload)
    21         {
    22             this.workload = workload;
    23         }
    24 
    25         @Override
    26         public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException
    27         {
    28             // Tell the user what you are doing
    29             monitor.beginTask("Copying files", workload);
    30 
    31             // Do your work
    32             for(int i = 0; i < workload; i++)
    33             {
    34                 // Optionally add subtasks
    35                 monitor.subTask("Copying file " + (i+1) + " of "+ workload + "...");
    36 
    37                 Thread.sleep(2000);
    38 
    39                 // Tell the monitor that you successfully finished one item of "workload"-many
    40                 monitor.worked(1);
    41 
    42                 // Check if the user pressed "cancel"
    43                 if(monitor.isCanceled())
    44                 {
    45                     monitor.done();
    46                     return;
    47                 }
    48             }
    49 
    50             // You are done
    51             monitor.done();
    52         }
    53 
    54     }
    55 }
  • 相关阅读:
    VMware Workstation-虚拟机的安装
    Linux操作系统-命令-free
    Linux操作系统-命令-vmstat
    抛出一个异常
    字符集
    页面缓存
    表单域
    弹出式说明
    canselBubble 和 stopPropagation理解
    JS---递归函数理解
  • 原文地址:https://www.cnblogs.com/kira2will/p/6256947.html
Copyright © 2011-2022 走看看