SWT概述
SWT是IBM公司开发的UI开发组件,它与AWT/SWING组件类似,但是SWT克服了AWT/SWING中许多问题,所以用SWT编写UI程序无论在美观成都还是响应速度上都远远超越了AWT和SWING.这主要是因为AWT只是单纯模拟本地操作系统窗口组件,而SWT最大化了操作系统的图形构件API,也就是说只要操作系统提供了图形构件,SWT就可以利用JNI调用他们,只有操作系统中不提供的组件SWT才会去模拟实现. 由于使用了JNI,使得它和本地操作系统紧密连接在一起,因此编写的界面和本地系统窗口几乎没有区别.JFace是SWT的一个增强库,它以来SWT并将其扩展,功能强大. 目前企业级的Java开发应用都会用到这个。
调用关系:
JFaceàSWTàJNIà--à本地操作系统窗口组件
安装
下载SWT安装的Jar包(注意操作系统),也可以在eclipse的plugin目录中找到(SWT.jar),然后用WinRAR解压缩得到org.eclipse.swt.win32.win32.x86_3.4.1.v3449c.jar以及5个dll文件,如果已经配置好了JDK,那么将jar文件复制到JDK/jre/lib/ext/中,将dll文件复制到JDK/jre/bin/目录下,就完成了安装。
http://zhidao.baidu.com/question/130025979.html?fr=ala0
一、SWT程序起步
第一个SWT程序:实现了一个记事本
package swt;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import java.io.*;
public class FirstSWT {
private static String fn = "";
private static Display display;
private static Shell shell;
private static Text text;
private Button newButton;
private Button openButton;
private Button saveButton;
private Button delButton;
private Button quitButton;
public FirstSWT(){
display = new Display();
//基本对话框
shell = new Shell(display,SWT.DIALOG_TRIM);
shell.setText("Note pad");
shell.setSize(600,400);
newButton = new Button(shell,SWT.PUSH);
newButton.setLocation(2,5);
newButton.setSize(50,20);
newButton.setText("new");
openButton = new Button(shell,SWT.PUSH);
openButton.setLocation(60,5);
openButton.setSize(50,20);
openButton.setText("open");
saveButton = new Button(shell,SWT.PUSH);
saveButton.setLocation(118,5);
saveButton.setSize(50,20);
saveButton.setText("save");
delButton = new Button(shell,SWT.PUSH);
delButton.setLocation(180,5);
delButton.setSize(50,20);
delButton.setText("delete");