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 }
  • 相关阅读:
    03014_properties配置文件
    Python 文件I/O
    Python面向对象
    Python CGI编程
    Python正则表达式
    Python使用SMTP发送邮件
    python操作mysql数据库
    Python多线程
    python XML解析
    给傻瓜用的SP2010开发--第一部分--理解SP开发平台--第一章节--理解SP促销讨论(2)--追踪SP源头
  • 原文地址:https://www.cnblogs.com/kira2will/p/6256947.html
Copyright © 2011-2022 走看看