swt进度条 线程
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进度条 线程的更多相关文章
- 使用线程新建WPF窗体(公用进度条窗体)
使用线程新建窗体 项目中需要一个公用的进度条窗体.大家知道在wpf中,有两个线程,一个是UI线程,另一个是监听线程(一直监听用户的输入).如果我们后台有阻塞UI线程的计算存在,那么界面上的比如进度条什 ...
- Android中通过线程实现更新ProgressDialog(对话进度条)
作为开发者我们需要经常站在用户角度考虑问题,比如在应用商城下载软件时,当用户点击下载按钮,则会有下载进度提示页面出现,现在我们通过线程休眠的方式模拟下载进度更新的演示,如图(这里为了截图方便设置对话进 ...
- (委托事件处理)关于多线程执行显示进度条的实例(转)&&线程间操作无效: 从不是创建控件“rtxtEntryNO”的线程访问它。
关于多线程执行显示进度条的实例! 之前回答了一篇关于怎么在线程中操作进度条的帖子,估计有人看的不是很明白今天没事,写了一个小小的实例,很简单,就2个文件权当抛砖引玉,希望有更好解决方案的人发表一下意见 ...
- C# 通过线程来控制进度条(转)--讲解多线程对界面的操作
// 通过创建委托解决传递参数问题 private void _btnRun_Click( object sender, System.EventArgs e ) { RunTaskDelegate ...
- Winform之跨线程访问控件(在进度条上显示字体)
此文章对于遇到必须使用线程但是没有办法在线程内操作控件的问题的处理 有很好的解决方案(个人认为的.有更好的方案欢迎交流.) 在做跨线程访问之前我们先了解下我们所做的需要达到的效果: 这个是批量的将x ...
- Handler实现线程之间的通信-下载文件动态更新进度条
1. 原理 每一个线程对应一个消息队列MessageQueue,实现线程之间的通信,可通过Handler对象将数据装进Message中,再将消息加入消息队列,而后线程会依次处理消息队列中的消息. 2. ...
- Delphi 转圈 原型进度条 AniIndicator 及线程配合使用
Delphi FMX 转圈 原型进度条 progress AniIndicator TAniIndicator TFloatAnimation VCL下也有转圈菊花进度条 TActivityIndic ...
- C#使用进度条,并用线程模拟真实数据 ProgressBar用法(转)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 关于JFace中的进度条对话框(ProgressMonitorDialog类)
在Windows操作系统中,最常用的进度条对话框就是文件复制时的弹出框,如果想让用户愉快的使用你开发 的软件,那么在执行某个较长时间的操作时候,就应该弹出一个进度条提示框,告诉用户程序正在做什么. 做 ...
随机推荐
- Win7开启SNMP服务
通过SNMP监控Windows主机需要在被监控的服务器上安装简单网络管理协议(SNMP)的Windows组件,以Windows 7系统为例: 首先,在控制面板中找到“卸载程序”: 在弹出的窗口中单击“ ...
- [SDOI2008]仪仗队 (欧拉函数)
题目描述 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线所及的学生人数来判断队伍是否整齐(如下图 ...
- Win10下安装虚拟机提示“Intel VT-x处于禁用状态”如何解决
今天在自己的笔记电脑上想安装一个Kali虚拟机学习用,安装的时候遇到这个问题,提示"Intel VT-x处于禁用状态". 要进入Win10的BIOS,先进入"设置&quo ...
- uva 10515 规律打表
Problem G Power et al. Input: Standard Input Output: Standard Output Finding the exponent of any num ...
- CSS参数介绍
原文发布时间为:2008-08-03 -- 来源于本人的百度文章 [由搬家工具导入] 行高 line-height: 16px 宽度 (具体位置)-width: 16px 文字 ...
- set_include_path() &&get_include_path()用法
function initialize(){ set_include_path(get_include_path().PATH_SEPARATOR . "core/"); ...
- 很好的linux下GPIO驱动详解文章
原文地址 http://blog.csdn.net/llxmedici/article/details/6282372 打算跟着友善之臂的<mini2440 linux移植开发指南>来做 ...
- hdu 3594 Cactus /uva 10510 仙人掌图判定
仙人掌图(有向):同时满足:1强连通:2任何边不在俩个环中. 个人理解:其实就是环之间相连,两两只有一个公共点,(其实可以缩块),那个公共点是割点.HDU数据弱,网上很多错误代码和解法也可以过. 个人 ...
- T3186 队列练习2 codevs
http://codevs.cn/problem/3186/ 题目描述 Description (此题与队列练习1相比改了2处:1加强了数据 2不保证队空时不会出队)给定一个队列(初始为空),只有两种 ...
- IoT设备程序开发及编译环境搭建初体验
引言 Mirai事件一经曝出,立即引领了一轮研究IoT设备的热潮.目前,对Mirai的报告大多只是在对其功能实现上的介绍,却很少提及如何实现IoT设备程序开发的测试环境.本文在对Mirai的源码研究的 ...