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 }
  • 相关阅读:
    MySQL学习(一) 概述
    Spring Tool Suite生成默认的MVC项目的配置文件问题
    [国家集训队]排队
    「PKUSC2018」最大前缀和
    「PKUSC2018」真实排名
    Min-Max容斥 & FMT
    SPOJ-CLFLARR 题解
    FFT详解
    CF Round#446 改题
    [CF1131D]Gourmet Choice 题解
  • 原文地址:https://www.cnblogs.com/kira2will/p/6256947.html
Copyright © 2011-2022 走看看