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();
  • 相关阅读:
    typescript泛型
    安卓手机IPhone抓包Https
    js里面for循环的++i与i++
    http请求头
    从浏览器地址栏输入url到页面呈现
    docker部署nodejs应用
    mac下使用MongoDB
    使用vue-cli3&vue ui图形化界面创建项目
    javascript中的call, apply(转载)
    跨域请求
  • 原文地址:https://www.cnblogs.com/thinkCoding/p/1725828.html
Copyright © 2011-2022 走看看