zoukankan      html  css  js  c++  java
  • eclipse中任务进度的使用

    1.JFace中的进度条使用

    import java.lang.reflect.InvocationTargetException;
    import org.eclipse.core.runtime.IProgressMonitor;
    import org.eclipse.jface.dialogs.ProgressMonitorDialog;
    import org.eclipse.jface.operation.IRunnableWithProgress;
    import org.eclipse.swt.widgets.Shell;
    
    public class OrdinaryProgress{
        private Shell shell;
        public OrdinaryProgress(Shell parent) {
           this.shell=shell;
        }
        
        public void run(){
    	try {
    	    new ProgressMonitorDialog(shell).run(true, true, new IRunnableWithProgress(){
    	        public void run(IProgressMonitor monitor)
    	    	    throws InvocationTargetException, InterruptedException {
    	            monitor.beginTask("generate", 30);
    	            for (int i = 0; i < 100; i++) {
    			if(monitor.isCanceled())
    			{
    			     return ;
    			}
    			monitor.worked(1);
    			Thread.sleep(50);
    		    }
    	            monitor.done();
    	        }
    	    });
    	} catch (InvocationTargetException e) {
    	} catch (InterruptedException e) {
    	}
        }
    
        
    
    
    }
    
    

    2. 使用Eclipse提供的job

    代码
    Job searchJob = new Job("Task") {
    protected IStatus run(IProgressMonitor monitor) {
    try {
    monitor.beginTask(
    "", 100);

    for (int i = 0; i < 10; i++) {
    Thread.sleep(
    500);
    monitor.worked(
    10);
    }

    monitor.done();
    }
    catch (Exception e) {
    e.printStackTrace();
    }

    return Status.OK_STATUS;
    }
    };
    searchJob.setUser(
    true); // 是否需要弹出进度窗口
    searchJob.schedule();
  • 相关阅读:
    HDU 1068
    hdu6447
    HDU 6438
    网络赛的个人反思总结
    Bellman-ford 模板
    Pairs Forming LCM LightOJ
    POJ
    链式前向星
    POJ 3281 Dining
    游标遍历所有数据库循环执行修改数据库的sql命令
  • 原文地址:https://www.cnblogs.com/thinkCoding/p/1725828.html
Copyright © 2011-2022 走看看