mythread.java

来自「一个java swt的线程例子 用滚动的进度条显示线程 直观 对初学者有点用」· Java 代码 · 共 71 行

JAVA
71
字号
import java.util.Random;

import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Scale;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Spinner;


 class Mythread extends Thread{
	int sd=0;
	private int i=0;
	public threadtest thisme;
	int sleeptime=0;
	boolean taskrun=true;
	public boolean sleeptrue=false;



	public Mythread(threadtest thisme) {
		this.thisme=thisme;
	}
	public void run() {
		while (true) {
			if(i>100|i==0){
				i=0;
				sd1();
			}
			i++;
			if(sleeptrue){
				try {
					Thread.sleep(sleeptime);
					sleeptrue=false;
				} catch (InterruptedException e) {
					// TODO 自动生成 catch 块
					e.printStackTrace();
				}
				
			}
			sds();
			try {
				Thread.sleep(100-sd);
			} catch (InterruptedException e) {
				// TODO 自动生成 catch 块
				e.printStackTrace();
			}
		}		
	
		
	}
	private void sd1() {
		Display.getDefault().syncExec(new Runnable() {
			public void run() {
				thisme.sd();
			}
		});
	}
	private void sds() {
		Display.getDefault().syncExec(new Runnable() {
			public void run() {
//				System.out.println(i);
				thisme.sd(i);
			}
		});
	}

}

⌨️ 快捷键说明

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