转: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 }

 

转载于:https://www.cnblogs.com/kira2will/p/6256947.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值