import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell; import java.util.Random; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Scale;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Spinner; public class threadtest{
public threadtest thisme=this ;
private Spinner spinner_1;
private Scale scale;
ProgressBar progressBar;
private Button button;
private Button button_1;
private Button button_2;
Button button_3;
private Button button_4;
private Button button_5;
private Button button_6;
private Button button_7;
private Group group;
Spinner spinner;
private Mythread mythread;
protected Shell shell;
/**
* Launch the application
* @param args
*/
public static void main(String[] args) {
try {
threadtest window = new threadtest();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
} /**
* Open the window
*/
public void open() {
final Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
} /**
* Create contents of the window
*/
protected void createContents() {
shell = new Shell();
shell.setLayout(new GridLayout());
shell.setSize(500, 375);
shell.setText("SWT Application");
//
oo(shell);
} void oo(Shell shell2) {
// TODO 自动生成方法存根
group = new Group(shell2, SWT.NONE);
group.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
// group = new Group(shell, SWT.NONE);
final GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 8;
group.setLayout(gridLayout);
group.setText("线程一");
button = new Button(group, SWT.NONE);
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
// System.out.println(spinner_1);
mythread = new Mythread(thisme);
mythread.start();
button.setEnabled(!button.getEnabled());
button_2.setEnabled(!button_2.getEnabled());
}
});
button.setText("启动"); button_2 = new Button(group, SWT.NONE);
button_2.setEnabled(false);
button_2.setText("停止");
button_2.addSelectionListener(new SelectionAdapter() {
@SuppressWarnings("deprecation")
public void widgetSelected(SelectionEvent arg0) {
mythread.stop();
button.setEnabled(!button.getEnabled());
button_2.setEnabled(!button_2.getEnabled());
}
}); button_1 = new Button(group, SWT.NONE);
button_1.setEnabled(false);
button_1.setText("暂停"); button_4 = new Button(group, SWT.NONE);
button_4.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
mythread.sleeptime=spinner_1.getSelection();
mythread.sleeptrue=true;
System.out.println(spinner_1.getSelection());
}
});
button_4.setText("睡眠"); button_5 = new Button(group, SWT.NONE);
button_5.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
mythread.suspend();
}
});
button_5.setText("挂起"); button_6 = new Button(group, SWT.NONE);
button_6.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
mythread.resume();
}
});
button_6.setText("恢复"); spinner = new Spinner(group, SWT.BORDER); button_3 = new Button(group, SWT.TOGGLE);
button_3.setSelection(true);
button_3.setText("随机速度"); progressBar = new ProgressBar(group, SWT.NONE);
progressBar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 8, 1)); new Label(group, SWT.NONE).setText("休眠"); spinner_1 = new Spinner(group, SWT.BORDER);
spinner_1.setMaximum(10000);
spinner_1.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
scale.setSelection(spinner_1.getSelection());
}
}); new Label(group, SWT.NONE).setText("毫秒"); scale = new Scale(group, SWT.NONE);
scale.setRedraw(true);
scale.setPageIncrement(1000);
scale.setIncrement(1000);
scale.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
spinner_1.setSelection(scale.getSelection());
}
});
scale.setMaximum(10000);
scale.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 5, 1)); } public void sd(int ss) {
mythread.sd=spinner.getSelection();
progressBar.setSelection(ss++);
} public void sd() {
if(button_3.getSelection()){
spinner.setSelection((int) (new Random().nextDouble()*100));
}
} }
 import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell; 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) {
e.printStackTrace();
} }
sds();
try {
Thread.sleep(100-sd);
} catch (InterruptedException e) {
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);
}
});
} }
 import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Scale;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Spinner; public class thread { private Spinner spinner_1;
private Scale scale;
private ProgressBar progressBar;
public Button button;
public Button button_1;
public Button button_2;
public Button button_3;
public Button button_4;
public Button button_5;
public Button button_6;
public Button button_7;
protected Shell shell;
public Group group;
public Spinner spinner;
// Mythread mythread;
/**
* Launch the application
* @param args
*/
public static void main(String[] args) {
try {
thread window = new thread();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
} /**
* Open the window
*/
public void open() {
final Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
} /**
* Create contents of the window
*/
protected void createContents() {
shell = new Shell();
shell.setLayout(new GridLayout());
shell.setSize(500, 375);
shell.setText("SWT Application");
threadtest[] tt= new threadtest[6];
for (int i = 0; i < tt.length; i++) {
tt[i]=new threadtest();
}
for (int i = 0; i < tt.length; i++) {
tt[i].oo(shell);
}
} }

swt进度条 线程的更多相关文章

  1. 使用线程新建WPF窗体(公用进度条窗体)

    使用线程新建窗体 项目中需要一个公用的进度条窗体.大家知道在wpf中,有两个线程,一个是UI线程,另一个是监听线程(一直监听用户的输入).如果我们后台有阻塞UI线程的计算存在,那么界面上的比如进度条什 ...

  2. Android中通过线程实现更新ProgressDialog(对话进度条)

    作为开发者我们需要经常站在用户角度考虑问题,比如在应用商城下载软件时,当用户点击下载按钮,则会有下载进度提示页面出现,现在我们通过线程休眠的方式模拟下载进度更新的演示,如图(这里为了截图方便设置对话进 ...

  3. (委托事件处理)关于多线程执行显示进度条的实例(转)&&线程间操作无效: 从不是创建控件“rtxtEntryNO”的线程访问它。

    关于多线程执行显示进度条的实例! 之前回答了一篇关于怎么在线程中操作进度条的帖子,估计有人看的不是很明白今天没事,写了一个小小的实例,很简单,就2个文件权当抛砖引玉,希望有更好解决方案的人发表一下意见 ...

  4. C# 通过线程来控制进度条(转)--讲解多线程对界面的操作

    // 通过创建委托解决传递参数问题 private void _btnRun_Click( object sender, System.EventArgs e ) { RunTaskDelegate ...

  5. Winform之跨线程访问控件(在进度条上显示字体)

    此文章对于遇到必须使用线程但是没有办法在线程内操作控件的问题的处理  有很好的解决方案(个人认为的.有更好的方案欢迎交流.) 在做跨线程访问之前我们先了解下我们所做的需要达到的效果: 这个是批量的将x ...

  6. Handler实现线程之间的通信-下载文件动态更新进度条

    1. 原理 每一个线程对应一个消息队列MessageQueue,实现线程之间的通信,可通过Handler对象将数据装进Message中,再将消息加入消息队列,而后线程会依次处理消息队列中的消息. 2. ...

  7. Delphi 转圈 原型进度条 AniIndicator 及线程配合使用

    Delphi FMX 转圈 原型进度条 progress AniIndicator TAniIndicator TFloatAnimation VCL下也有转圈菊花进度条 TActivityIndic ...

  8. C#使用进度条,并用线程模拟真实数据 ProgressBar用法(转)

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  9. 关于JFace中的进度条对话框(ProgressMonitorDialog类)

    在Windows操作系统中,最常用的进度条对话框就是文件复制时的弹出框,如果想让用户愉快的使用你开发 的软件,那么在执行某个较长时间的操作时候,就应该弹出一个进度条提示框,告诉用户程序正在做什么. 做 ...

随机推荐

  1. BZOJ 2140 稳定婚姻 ——二分图

    论二分图的可行边与必须边. 考虑用dinic增广之后的图,一些是必要的割边,一些是可行的割边. 我们首先求出一组可行的最大匹配,那么这些变都是可行的. 然后我们求一遍强连通分量. 如果 scc[u]! ...

  2. 自己写的java返回结果集封装

    import java.io.Serializable; import com.fasterxml.jackson.core.JsonProcessingException; import com.f ...

  3. SPOJ 4060 A game with probability

    博弈论+dp+概率 提交链接- 题意不是很好懂 Ai 表示剩 i 个石头. A 先手的获胜概率. Bi 表示剩 i 个石头. B先手的获胜概率. 如果想选,对于 Ai: 有 p 的概率进入 Bi−1 ...

  4. 垃圾收集器与内存分配策略 (深入理解JVM二)

    1.概述 垃圾收集(Garbage Collection,GC). 当需要排查各种内存溢出.内存泄露问题时,当垃圾收集成为系统达到更高并发量的瓶颈时,我们就需要对这些“自动化”的技术实施必要的监控和调 ...

  5. web信息搜索之目标扫描篇

    https://blog.csdn.net/dongfei2033/article/details/78175421

  6. HDU - 5584 LCM Walk (数论 GCD)

    A frog has just learned some number theory, and can't wait to show his ability to his girlfriend. No ...

  7. c字符和字符数组/字符串

    一维和二维的都可以:一维的情况如下:1,char string0[10];2,char string1[]="prison break";3,char string2[100]=& ...

  8. python两个类之间变量和函数的调用

    1.class_a() class_b() 2.class_b使用class_a中的变量和函数 3.变量class_a中:class_a.num=... 函数class_b中:先实例化class_a( ...

  9. BUPT复试专题—众数(2014)

    题目描述 有一个长度为N的非降数列,求数列中出现最多的数,若答案不唯一输出最小的数 输入 第一行T表示测试数据的组数(T<100) 对于每组测试数据: 第一行是一个正整数N表示数列长度 第二行有 ...

  10. Mqtt协议IOS端移植3

    ServerMqFramework.h #import "MqttFramework.h" @interface ServerMqFramework : MqttFramework ...