SWT测试模板+同步异步Demo
来源:互联网 发布:推广淘宝联盟怎么转码 编辑:程序博客网 时间:2024/04/29 23:53
package test.run;import org.eclipse.swt.SWT;import org.eclipse.swt.events.SelectionAdapter;import org.eclipse.swt.events.SelectionEvent;import org.eclipse.swt.widgets.Button;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.Shell;import org.eclipse.swt.widgets.Text;public class TestTemplate {public static void main(final String[] args) {final Display display = new Display();final Shell shell = new Shell(display);shell.setText("SWT测试模板");shell.setBounds(800, 100, 400, 300);shell.open();final Label lblTest = new Label(shell, SWT.NONE);lblTest.setText("测试结果:");lblTest.setBounds(10, 10, 60, 20);final Text txtTest = new Text(shell, SWT.NONE | SWT.BORDER);txtTest.setBounds(70, 10, 80, 20);txtTest.setText("没点击按钮");final Button btnTest = new Button(shell, SWT.NONE);btnTest.setText("测试");btnTest.setBounds(160, 10, 40, 20);btnTest.addSelectionListener(new SelectionAdapter() {@Overridepublic void widgetSelected(final SelectionEvent e) {txtTest.setText("点击了按钮");printTime();// 同步是防止一个数据被两人同时用,造成数据的破坏,异步是为了加快程序的运行。// testAsyncExec();testSyncExec();}});while (!shell.isDisposed()) {if (!display.readAndDispatch()) {display.sleep();}}display.dispose();}/** * 异步asyncExec(同时访问一个资源,提高效率) */protected static void testAsyncExec() {System.out.println("这里不会因为asyncExec而阻塞,同时进行,就是异步");Display.getCurrent().asyncExec(new Runnable() {@Overridepublic void run() {try {System.out.println("开始倒计时10秒了");Thread.sleep(10000);// 倒计时10秒} catch (final InterruptedException e1) {}System.out.println("倒计时10秒完成了");}});new Thread(new Runnable() {@Overridepublic void run() {try {System.out.println("开始循环5秒");Thread.sleep(5000);// 循环5秒System.out.println("循环5秒停止");} catch (final InterruptedException e) {}}}).start();}/** * 同步syncExec(等待一个线程结束后才开始另一个,保护数据,防止脏读) */protected static void testSyncExec() {System.out.println("这里因为syncExec阻塞,要等到倒计时完成之后才会运行,就是同步");Display.getCurrent().syncExec(new Runnable() {@Overridepublic void run() {try {System.out.println("开始倒计时10秒了");Thread.sleep(10000);// 倒计时10秒} catch (final InterruptedException e1) {}System.out.println("倒计时10秒完成了");}});new Thread(new Runnable() {@Overridepublic void run() {try {System.out.println("开始循环5秒");Thread.sleep(5000);// 循环5秒System.out.println("循环5秒停止");} catch (final InterruptedException e) {}}}).start();}/** * 用于计时 */protected static void printTime() {new Thread(new Runnable() {@Overridepublic void run() {int i = 0;while (i < 16) {i++;try {Thread.sleep(1000);System.out.println(i + "秒");} catch (final InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}}).start();}}RCP,SWT,插件开发【qq群】336280109
0 0
- SWT测试模板+同步异步Demo
- GCD同步异步测试DEMO
- Eclipse的SWT测试模板
- MVCPager 分页: 异步和同步Demo
- socket demo,实现同步异步通信
- 线程同步与异步简单测试类
- swt 简单DEMO
- SWT List Demo
- 【测试】Gunicorn , uWSGI同步异步测试以及应用场景总结
- ajax同步异步详解与回调带参数实例测试
- ajax同步异步详解与回调带参数实例测试
- Android单元测试:测试RxJava的同步及异步操作
- 异步 同步
- 同步异步
- 同步异步
- 同步异步
- 同步异步
- 同步异步
- IOS 插件管理器及常见问题
- [046] 《微信公众平台应用开发:方法、技巧与案例》火热预售中...
- 攻击实例与防御
- (转载)Jvm工作原理学习笔记
- menu item home区域的的id
- SWT测试模板+同步异步Demo
- 重写完美Equals的方法
- GRE写作五段法
- 随记1
- Linux下的tar压缩解压缩命令详解
- [047] 即将陆续推出微信公众平台开发视频教程
- unity FPS 将原来的left,right控制左右移动改为控制向左向右旋转
- autolayout学习介绍------Masonry的使用
- This device has been locked for debugging.