SWT实例学习代码例子 -- 学好swt,色色就可以写桌面应用了

包名称 package cn.iamsese.swt.study ;

 

定义一个类来做运行时的入口,这样可以减少main方法的使用,使自己更能进入SWT的学习

 

/**
 * 运行控制器类
 */
 
public class Runner {
	

	public static void main(String[] args) {		
		SimpleShell simpleShell = new SimpleShell(ExampleClassName.DefaultWindow);
		//SimpleShell simpleShell = new SimpleShell(ExampleClassName.ChildShell);
	}	
}

 定义一个类用于分辨不同的demo例子,使得可以传入不同的构造函数到同一的构造函数处,以后没建立一个新实例,就在其中添加一个常数,使用16进制,因为好标识

 

/**
 * 实例类的名字 -- 通过在构造函数中调用不同的参数值来运行不同的实例程序
 * cn.iamsese.swt.study
 * Author: vb2005xu [JAVA菜鸟]
 */
interface ExampleClassName {
	public final static int DefaultWindow = 0x1 ; //缺省实例
	public final static int ChildShell = 0x2 ; //子窗口实例
}

 

导入的包 -- 以后按需要会添加

import org.eclipse.swt.* ;
import org.eclipse.swt.widgets.*;

 

 

每添加一个例子,就在其中添加一些代码,后面会陆续跟新一些模板代码,但是大体东西不变

 

/**
 * 所有例子的外壳代码
 * cn.iamsese.swt.study
 * Author: vb2005xu [JAVA菜鸟]
 */
class SimpleShell {
	private Display display ;
	private Shell shell ;
	
	public SimpleShell(String title){
		this.display = new Display();
		this.shell = new Shell(this.display);		
		this.shell.setText(title);
		this.shell.setSize(500,500);
		SimpleShellUtil.setShellAtCenter(this.shell);
	}
	
	public SimpleShell(int className){
		this("第一个SWT例子: cn.iamsese.swt.study.SimpleShell");
		this.shell.open();
		switch (className) {
			case ExampleClassName.ChildShell:
				this.childShellTest(this.shell);
				break;
	
			default:
				break;
		}
		
		while(! this.shell.isDisposed()){
			if ( ! this.display.readAndDispatch() ){
				this.display.sleep();
			}	
		}
		
		this.display.dispose();
	}
	
	public void childShellTest(Shell shell){
		//非模态对话框
		ChildShell child1 = new ChildShell(shell);
		//模式对话框 -- 只禁用父窗体
		ChildShell child2 = new ChildShell(shell,SWT.DIALOG_TRIM|SWT.APPLICATION_MODAL);		
		//模式对话框 -- 禁用系统窗体
		ChildShell child3 = new ChildShell(shell,SWT.DIALOG_TRIM|SWT.SYSTEM_MODAL);	
	}
}

 

 

代码例子1 -- ChildShell  每个代码例子,基本都是自包含的

/**
 * 子 窗口实例
 * cn.iamsese.swt.study
 * Author: vb2005xu [JAVA菜鸟]
 */
class ChildShell {
	
	public ChildShell(Shell parent)
	{
		Shell child = new Shell(parent);
		child.setText("第二个SWT例子: cn.iamsese.swt.study.ChildShell");
		child.setSize(400,100);
		child.open();	
	}
	public ChildShell(Shell parent,int style)
	{
		Shell child = new Shell(parent,style);
		child.setText("第二个SWT例子: cn.iamsese.swt.study.ChildShell");
		child.setSize(400,100);
		child.open();	
	}

}

 

 

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值