知识大全 基&
Posted 构件
篇首语:千金一刻莫空度,老大无成空自伤。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 基&相关的知识,希望对你有一定的参考价值。
一 SWT简介 Java语言的声望和它在桌面应用程序(GUI程序)所取得的成就显然极不相符 至今仍然很少能看到非常成功Java桌面程序 虽然有JBuilder Netbean JProbe等大型软件作为代表 但这仍不能证明Java的GUI程序是成功的 它们的外观总是和同一操作系统平台下的其它软件显得格格不入 对机器配置的需求也似乎永无止境 这使得它们只能被一些总是拥有当前最高性能PC的程序员们所容忍 或是那些不在乎金钱和时间的专业用户所接受 对绝大多数计算机使用者来说 AWT或SWING代表着怪异的界面和无法接受的速度 Standard Widget Toolkit(SWT)或许是Java这一噩梦的终结者 广大Java程序员终于可以开发出高效率的GUI程序 它们拥有标准的外观 几乎没有人能看出你的程序是用Java写出来的 更为重要的是 这些程序是跨平台的 SWT本身仅仅是Eclipse组织为了开发Eclipse IDE环境所编写的一组底层图形界面 API 或许是无心插柳 或是有意为之 至今为止 SWT无论是在性能和外观上 都超越了SUN公司提供的AWT和SWING 目前Eclipse IDE已经开发到了 版本 SWT已经十分稳定 这里指的稳定应该包含两层意思 一是指性能上的稳定 其中的关键是源于SWT的设计理念 SWT最大化了操作系统的图形构件API 就是说只要操作系统提供了相应图形的构件 那么SWT只是简单应用JNI技术调用它们 只有那些操作系统中不提供的构件 SWT才自己去做一个模拟的实现 可以看出SWT的性能上的稳定大多时候取决于相应操作系统图形构件的稳定性 另一个稳定是指SWT API包中的类 方法的名称和结构已经少有改变 程序员不用担心由于Eclipse组织开发进度很快(Eclipse IDE每天都会有一个Nightly版本的发布) 而导致自己的程序代码变化过大 从一个版本的SWT更新至另一版本 通常只需要简单将SWT包换掉就可以了 二 Eclipse 的SWT编程 SWT比AWT和Swing要快多 因为它是利用操作系统的界面组件生成UI的 在java桌面设计领域掀起一场革命 环境配置 windows系统+eclipse 具体操作 ( ) 新建一java项目 命名SWT 文件结构如下 +swt +bin(编译输出) +src(原文件) +AddressBookUI java +swt awt win dll(以下均从eclipse\\plugins\\ eclipse swt win _ \\os\\win \\x 下导入) +swt win dll +javaw exe manifest ( ) 到项目的properties里 在java build path | libraries里将swt jar导入 ( ) AddressBookUI java原代码如下 import eclipse swt widgets Display; import eclipse swt widgets Shell; import eclipse swt SWT; import eclipse swt widgets Button; import eclipse swt widgets Group; import eclipse swt widgets Label; import eclipse swt widgets Text; import eclipse swt widgets *; import eclipse swt events SelectionAdapter; import eclipse swt events SelectionEvent; public class AddressBookUI private Shell shell; private Text miscText; private Text addrText; private Text emailText; private Text phoneText; private Text lnameText; private Text fnameText; private Button cancelButton; private Button saveButton; private Button nextButton; private Button prevButton; private Button editButton; private Button deleteButton; private Button newButton; public static void main(String[] args) AddressBookUI window = new AddressBookUI(); window open(); public void open() final Display display = new Display(); shell = new Shell(); shell setSize( ); shell setText( Address Book ); newButton = new Button(shell SWT NONE); newButton addSelectionListener(new SelectionAdapter() public void widgetSelected(SelectionEvent e) clearText(); setTextEditable(true); enableEditButtons(false); enableSaveButtons(true); System out println( New button selected ); ); newButton setBounds( ); newButton setText( New ); deleteButton = new Button(shell SWT NONE); deleteButton addSelectionListener(new SelectionAdapter() public void widgetSelected(SelectionEvent e) clearText(); System out println( Delete button selected ); ); deleteButton setBounds( ); deleteButton setText( Delete ); editButton = new Button(shell SWT NONE); editButton addSelectionListener(new SelectionAdapter() public void widgetSelected(SelectionEvent e) setTextEditable(true); enableEditButtons(false); enableSaveButtons(true); System out println( Edit button selected ); ); editButton setBounds( ); editButton setText( Edit ); prevButton = new Button(shell SWT NONE); prevButton addSelectionListener(new SelectionAdapter() public void widgetSelected(SelectionEvent e) System out println( Previous button selected ); ); prevButton setBounds( ); prevButton setText( Previous ); nextButton = new Button(shell SWT NONE); nextButton addSelectionListener(new SelectionAdapter() public void widgetSelected(SelectionEvent e) System out println( Next button selected ); ); nextButton setBounds( ); nextButton setText( Next ); saveButton = new Button(shell SWT NONE); saveButton addSelectionListener(new SelectionAdapter() public void widgetSelected(SelectionEvent e) setTextEditable(false); enableEditButtons(true); enableSaveButtons(false); System out println( Save button selected ); ); saveButton setBounds( ); saveButton setText( Save ); saveButton setEnabled(false); cancelButton = new Button(shell SWT NONE); cancelButton addSelectionListener(new SelectionAdapter() public void widgetSelected(SelectionEvent e) setTextEditable(false); enableEditButtons(true); enableSaveButtons(false); System out println( Cancel button selected ); ); cancelButton setBounds( ); cancelButton setText( Cancel ); cancelButton setEnabled(false); final Group group = new Group(shell SWT NONE); group setText( Details ); group setBounds( ); final Label label = new Label(group SWT NONE); label setBounds( ); label setText( First Name: ); final Label label = new Label(group SWT NONE); label setBounds( ); label setText( Last Name: ); final Label label = new Label cha138/Article/program/Java/ky/201311/28751相关参考