progressmonitordialog3.java

来自「SWTJFace篇项目源程序该项目包含 包含了Eclipse下构建swt的基本」· Java 代码 · 共 55 行

JAVA
55
字号
package cn.com.chengang.jface.dialog.loopprogressdialog;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;


public class ProgressMonitorDialog3 {

	public static void main(String[] args) {
		new ProgressMonitorDialog3().open();
	}

	public void open() {
		final Display display = Display.getDefault();
		final Shell shell = new Shell();
		shell.setSize(500, 375);

		shell.setLayout(new RowLayout());
		Button button = new Button(shell, SWT.NONE);
		button.setText("        GO          ");
		button.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				new LoopProgressDialog(shell).run(true, new IProgressDialogRunnable() {
					public void run(BooleanFlag stopFlag) {
						for (int i = 0; i < 10; i++) {
							System.out.println("第" + (i + 1) + "个任务执行完毕");
							if (stopFlag.getFlag()) {
								System.out.println("被中断了");
								return;
							}
							try {
								Thread.sleep(1000);
							} catch (Throwable t) {}
						}
						stopFlag.setFlag(true);
						System.out.println("全部任务执行完毕");
					}
				});
			}
		});

		shell.layout();
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?