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. hdfs api读写文写件个人练习

    看下hdfs的读写原理,主要是打开FileSystem,获得InputStream or OutputStream: 那么主要用到的FileSystem类是一个实现了文件系统的抽象类,继承来自org. ...

  2. [BZOJ3054] Rainbow的信号(考虑位运算 + DP?)

    传送门 BZOJ没数据范围... 其实数据范围是这样的.. 前20%可以直接n^3暴力枚举每个区间 前40%可以考虑每一位,因为所有数每一位都是独立的,而和的期望=期望的和,那么可以枚举每一位,再枚举 ...

  3. JMS API学习总结(一)

    三.JMS API简析 顶级接口 P2P Pub/sub 备注 ConnectionFactory QueueConnectionFactory TopicConnectionFactory 基于工厂 ...

  4. 【leetcode最短路】818. Race Car

    https://leetcode.com/problems/race-car/description/ 1. BFS剪枝 0<=current position<=2*target.为什么 ...

  5. C#.net磁盘管理以及文件操作

    原文发布时间为:2008-08-08 -- 来源于本人的百度文章 [由搬家工具导入]    需要引入的命名空间: using System.IO;using System.Text; private ...

  6. php——两种无限级分类

    /** * 无级递归分类 TP框架 * @param int $assortPid 要查询分类的父级id * @param mixed $tag 上下级分类之间的分隔符 * @return strin ...

  7. 关于整合spring+mybatis 第二种方式

    和第一种方式一样的步骤,不过bean.xml中有些许差异 <!-- 配置sqlSessionFactory --> <bean id="sqlSessionFactory& ...

  8. CentOS 7.3 源码安装 OpenVAS 9

    https://my.oschina.net/u/2613235/blog/1583198

  9. Java中的类反射

    一.反射的概念 : 反射的概念是由Smith在1982年首次提出的,主要是指程序可以访问.检测和修改它本身状态或行为的一种能力.这一概念的提出很快引发了计算机科学领域关于应用反射性的研究.它首先被程序 ...

  10. JAVA获取前一个月的第一天和最后一天

    package com.date; import java.text.SimpleDateFormat; import java.util.Calendar; /** * 默认显示前一个月的第一天和最 ...