The Goal
Keep walking……
posts - 23,  comments - 1,  trackbacks - 0
  • Model-based adapters

与SWT widgets一起工作的JFace类可称为model-based adapters [或helper classes].这些adapter可以分为4类:
1.Viewers
将GUI组件中的信息与外观分离 [与SWT不同]
2.Actions and contributions
简化了事件的处理,将用户命令的反应与引发反应的事件分离
3.Image and font registries
注册机制,资源可以被按需分配和释放

4.Dialogs and wizards
信息框、错误框、进度框与向导框等

  • SET/JFace应用程序的三段式结构

package com.swtjface.Ch2;

import org.eclipse.jface.window.*;

import org.eclipse.swt.*;

import org.eclipse.swt.widgets.*;


public class HelloSWT_JFace extends ApplicationWindow {

public HelloSWT_JFace() {

super(null); //1.Window allocation

}

protected Control createContents(Composite parent) {

Text helloText = new Text(parent, SWT.CENTER);

helloText.setText("Hello SWT and JFace!");

parent.pack();

return parent; //2.Window presentation

/*处理窗口的设计,由于ApplicationWindow的可视部分不能被直接access,此方法连同一个Composite来控制GUI的显示,此container对象[Composite]是所有被加入应用程序的GUI组件的父件*/

}

public static void main(String[] args) {

HelloSWT_JFace awin = new HelloSWT_JFace();

awin.setBlockOnOpen(true);

awin.open();

Display.getCurrent().dispose();  //3.Window operation

/*负责GUI的实际运作。在分派好ApplicationWindow的资源之后,main方法使窗口显示,当setBlockOnOpen()方法以一个true参数被调用的时候,窗口关闭。然后ApplicationWindow的open()方法被调用,根据createContent()方法所返回的Composite来显示窗口。然后程序通过dispose()方法释放GUI的Display实例.因为此程序中的所有widget都是display的child,所以一旦释放Display,所有的widget都被释放*/

}

}

  • SWT与SWT/JFace的区别

SWT将GUI的外观和操作都放在它的Shell类里,而SWT/JFace却将两者分离开来了,其中外观由createContents()方法内的Compsite来控制,而操作部分大体上是通过ApplicationWindow类的实例来实现的。

  • ApplicationWindow

SWT/JFace同样需要一个单独的Display实例,但是只要ApplicationWindow通过一个null参数来构建,那么就会创建它自己的Shell。参阅下图

ApplicationWindow在Shell的基础上提供了更多的途径来设计窗口,其相关方法如下:
addMenuBar()
Configures the window with a top-level menu
addToolBar()
Adds a toolbar beneath the main menu
addStatusLine()
Creates a status area at the bottom of the window
setStatus(String)
Displays a message in the status area
getSeparator()
Returns the line separating the menu from the window
setDefaultImage(Image)
Displays an image when the application has no shell
setExceptionHandler(IExceptionHandler)
Configures the application to handle exceptions according to the specified interface

posted on 2006-03-15 17:07 JOO 阅读(312) 评论(0)  编辑  收藏 所属分类: SWT & JFace IN ACTION

只有注册用户登录后才能发表评论。


网站导航:
 
Hit the target!

<2006年3月>
2627281234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(2)

随笔分类(23)

随笔档案(22)

文章档案(1)

相册

Neighbor

搜索

  •  

最新评论

阅读排行榜

评论排行榜