java jface swt_JAVA.SWT/JFace: 入门介绍

《Eclipse SWT/JFACE 核心应用》 清华大学出版社

import org.eclipse.swt.SWT;

import org.eclipse.swt.widgets.Button;

import org.eclipse.swt.widgets.Display;

import org.eclipse.swt.widgets.Shell;

public class HelloWorld {

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

// 1. 初始化窗口

Display display = new Display();

Shell shell = new Shell(display);

shell.setText("SWT");   // 设置窗口标题

// 2. 向Shell中添加Widget空间

Button button = new Button(shell, SWT.CENTER);

button.setText("欢迎进入SWT的世界!");

button.pack();

// 3. GUI调用

shell.pack(); // 调整布局

shell.open(); // 打开窗口

while (!shell.isDisposed()) {

if (!display.readAndDispatch()) {

display.sleep();

}

}

// 销毁Display实例,释放创建Display时所获取的内存资源,断开与本地操作系统的连接

display.dispose();

}

}

*******************************************************************************************

SWT应用程序的组成:

一个SWT应用程序的基本组成部分为显示界面(Display)、命令界面(Shell,使命令进入并使运行初始化)和窗口部件(Widgets)。Display负责管理事件循环和控制UI线程和其他线程之间的通讯。Shell是应用程序中被操作系统窗口管理器管理的窗口。每个SWT应用程序至少需要一个Display和大于等于1个的Shell实例。0818b9ca8b590ca3270a3433284dd417.png

图1:从不同的角度看SWT应用程序

图1从不同的角度展示了SWT应用程序。左侧的图是一个简化的UI对象的继承图。中间的图展示了UI对象的容器结构(containment structure)。右侧的图则是创建后的UI外观。

如果一个应用程序使用了多个线程,那么每个线程都使用的是Display对象分配给它自己的实例。程序员可以使用静态方法Display.getCurent()来得到Display对象的当前活动的实例。

Shell用于在特定的操作系统中表现窗口。Shell可以最大化、最小化或正常化。Shell有两种类型。第1种是高层shell,它是Display的子窗口,同时它也是一个主窗口。第2类是对话shell,这种shell要依赖于其他的shell窗口存在。shell窗口最终成为上述那种类型,要看在创建shell时传递给shell构造函数的是什么风格位(style bits)。一个shell的默认值是DialogShell。也就是说,如果不带参数,那默认就是一个对话shell。而如果给参数赋予了一个Display对象,则该shell将是一个高层shell。

一些窗口部件的属性必须在创建它们的初期就要被设置。这些窗口部件的属性就是前面所说的风格位(style bits)。在SWT的类中,风格位被定义为常数。例如,Button button = new Button( shell, 〈styleBits〉 )。可以使用或(OR)操作符“|”来设置多个风格位。例如,如果想设置一个带边界的压下按钮,需要传递SWT.PUSH | SWT.BORDER作为风格位参数。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
org.xml.sax.SAXParseException; systemId: file:/D:/app.uix; lineNumber: 1; columnNumber: 1; 文件提前结束。 at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327) at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1437) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:1019) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213) at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643) at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:327) at javax.xml.parsers.SAXParser.parse(SAXParser.java:328) at com.android.uiautomator.tree.UiHierarchyXmlLoader.parseXml(UiHierarchyXmlLoader.java:130) at com.android.uiautomator.UiAutomatorModel.<init>(UiAutomatorModel.java:51) at com.android.uiautomator.actions.OpenFilesAction.run(OpenFilesAction.java:55) at org.eclipse.jface.action.Action.runWithEvent(Action.java:498) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584) at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501) at org.eclipse.jface.action.ActionContributionItem$6.handleEvent(ActionContributionItem.java:452) at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source) at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source) at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source) at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source) at org.eclipse.jface.window.Window.runEventLoop(Window.java:825) at org.eclipse.jface.window.Window.open(Window.java:801) at com.android.uiautomator.UiAutomatorViewer.main(UiAutomatorViewer.java:78) null rootnode after parsing.
最新发布
07-14

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值