转自:http://lggege.iteye.com/blog/232964
public class XmindTest {
public static void main(String[] args) {
Display.getDefault();
ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(null);
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("任务", 100);
for (int i = 0; i < 10 && !monitor.isCanceled(); i++) {
Thread.sleep(500);
monitor.worked(10);
monitor.subTask("第" + i + "个任务");
}
monitor.done();
}
};
try {
progressDialog.run(true,/*是否开辟另外一个线程*/
true,/*是否可执行取消操作的线程*/
runnable/*线程所执行的具体代码*/
);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

本文展示了一个使用XMind进行进度监控的Java示例代码。通过ProgressMonitorDialog和IRunnableWithProgress接口,实现了任务进度的更新与显示。该示例在主函数中创建了进度对话框,并定义了一个具体任务的可运行接口实现,通过循环和sleep模拟长时间任务,并更新进度条。
425

被折叠的 条评论
为什么被折叠?



