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將GUI的外觀和操作都放在它的Shell類里,而SWT/JFace卻將兩者分離開來了,其中外觀由createContents()方法內的Compsite來控制,而操作部分大體上是通過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 閱讀(325)
評論(0) 編輯 收藏 所屬分類:
SWT & JFace IN ACTION