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. ngrinder的安装

    1.官网下载war包(ngrinder-controller),可以使用tomcat启动或者直接nohup java -XX:Permsize=200m -jar ngrinder-3.4.1.war ...

  2. 玩转css样式选择器----当父元素只有一个子元素时居中显示,多个水平排列

  3. Laravel 数据库操作之Eloquent ORM模型

    //模型中的相关代码 namespace App; use Illuminate\Database\Eloquent\Model; class Student extends Model{ //默认对 ...

  4. pl/sql小技巧

    更正方法: 然后把Automatic statistics的勾选去掉,点击apply即可

  5. spring boot--常用配置

    spring boot 需要引用的依赖项: spring-boot-starter-parent // 所有Spring Boot组件的基础引用 spring-boot-starter-web // ...

  6. qu de hanzi 首字母

    Function hztopy(hzpy As String) As StringDim hzstring As String, pystring As StringDim hzpysum As In ...

  7. 关于傅里叶变换NTT(FNT)的周边

    NTT:快速数论变化,对于FFT精度减少的情况,NTT可以避免但是会慢一点,毕竟是数论有Mod,和快速米 引用:http://blog.csdn.net/zz_1215/article/details ...

  8. Hadoop HDFS 常用命名

    HDFS命令基本格式:hadoop fs -cmd < args > ls 命令hadoop fs -ls / 列出hdfs文件系统根目录下的目录和文件 hadoop fs -ls -R ...

  9. 深入理解iPhone数据持久化(手把手教你iphone开发 – 基础篇)

    在所有的移动开发平台数据持久化都是很重要的部分:在j2me中是rms或保存在应用程序的目录中,在symbian中可以保存在相应的磁盘目录中和数据库中.symbian中因为权限认证的原因,在3rd上大多 ...

  10. 深入理解javascript之设计模式

    设计模式 设计模式是命名.抽象和识别对可重用的面向对象设计实用的的通用设计结构. 设计模式确定类和他们的实体.他们的角色和协作.还有他们的责任分配. 每个设计模式都聚焦于一个面向对象的设计难题或问题. ...