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操作系统中,最常用的进度条对话框就是文件复制时的弹出框,如果想让用户愉快的使用你开发 的软件,那么在执行某个较长时间的操作时候,就应该弹出一个进度条提示框,告诉用户程序正在做什么. 做 ...
随机推荐
- 谈Elasticsearch下分布式存储的数据分布
对于一个分布式存储系统来说,数据是分散存储在多个节点上的.如何让数据均衡的分布在不同节点上,来保证其高可用性?所谓均衡,是指系统中每个节点的负载是均匀的,并且在发现有不均匀的情况或者有节点增加/删除 ...
- BZOJ 4004 [JLOI2015]装备购买 ——线性基
[题目分析] 题目很简单,就是要维护一个实数域上的线性基. 仿照异或空间的线性基的方法,排序之后每次加入一个数即可. 卡精度,开long double 和 1e-6就轻松水过了. [代码] #incl ...
- indexedDB 增删改查
/** * 打开数据库 */ export function openDB() { return new Promise((resolve, reject) => { let indexedDB ...
- python3里的Urllib库
首先Urllib是python内置的HTTP请求库. 包括以下模块: urllib.request 请求模块: urllib.error 异常处理模块: urllib.parse url解析模块: u ...
- 使用 ftrace 调试 Linux 内核,第1部分
ftrace 是 Linux 内核中提供的一种调试工具.使用 ftrace 可以对内核中发生的事情进行跟踪,这在调试 bug 或者分析内核时非常有用.本系列文章对 ftrace 进行了介绍,分为三部分 ...
- Tomcat 7 的domain域名配置,Tomcat 修改JSESSIONID
https://blog.csdn.net/catoop/article/details/64581325
- ubuntu下安装jdk、tomcat、mysql
1.JDK安装 方法1: 将JDK安装包解压缩之后,编辑~/.bashrc文件,在该文件里面加入下面的配置,然后通过source ~/.bashrc.JDK即安装成功. export JAVA_HOM ...
- T3186 队列练习2 codevs
http://codevs.cn/problem/3186/ 题目描述 Description (此题与队列练习1相比改了2处:1加强了数据 2不保证队空时不会出队)给定一个队列(初始为空),只有两种 ...
- IntelliJ IDE 各种插件的安装和使用
插件的安装和使用持续的更新中...........................................................
- Windows 10安装IntelliJ IDEA时快捷键冲突设置
Windows的快捷键的非常多,而且个性化软件获得这些权限的也很多,所以没有最终的方法,只能不断的发现和尝试. 下面是收集的一些教程,或许能在这里找到灵感: 切记:不建议优先修改IDEA的快捷键,应该 ...