第三章 第六节 SWT类的常量与函数

本文详细介绍了SWT类的类级别常量和方法,包括如何使用error、getMessage、getPlatform和getVersion等方法,以及SWT类提供的消息键和值,通过实例代码演示了获取平台和版本号的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第六节 SWT类的常量与函数

返回目录

 

SWT类有一堆类级别(class-level)的常量和方法用来简化SWT编程。

没有什么事情阻止您创建一个SWT对象,因为创建一个不会带来任何坏处。SWT类继承于java.lang.Object,它没有定义构造函数,所以默认的构造函数会被调用。然而,一个SWT对象除了继承于java.lang.Object的状态,没有任何状态(state),本质上这些状态也是没什么用的。

SWT类提供了一些有用的方法,像前面提到的,都是静态的(static)。大多数程序不必用到这些方法;它们在表3-6中列出。

3-6: SWT 的方法

方法

说明

static void error(int code)

Throws an exception based on code. It's the same as calling static void error(int code, (Throwable) null).

static void error(int code, Throwable throwable)

Throws an exception based on code. throwable should either be null or the Throwable that caused SWT to throw an exception. code is one of the error constants defined in SWT.

static String getMessage (String key)

Gets the appropriate National Language Support (NLS) message as a String for key. See java.util.ResourceBundle for more information on NLS. The resource bundle is found in org.eclipse.swt.internal.SWTMessages .properties; see Table 3-7 for the supported keys and corresponding messages.

static String getPlatform()

Gets the SWT platform name (for example, "win32," "gtk," "carbon").

static int getVersion()

Gets the SWT library version number.

 

3-7: SWT消息的键(Key)和值(value)

SWT_Yes

Yes

SWT_No

No

SWT_OK

OK

SWT_Cancel

Cancel

SWT_Abort

Abort

SWT_Retry

Retry

SWT_Ignore

Ignore

SWT_Sample

Sample

SWT_A_Sample_Text

A Sample Text

SWT_Selection

Selection

SWT_Current_Selection

Current Selection

SWT_Font

Font

SWT_Color

Color

SWT_Extended_style

Extended style

SWT_Size

Size

SWT_Style

Style

SWT_Save

Save

SWT_Character_set

Character set

SWT_ColorDialog_Title

Colors

SWT_FontDialog_Title

Fonts

SWT_Charset_Western

Western

SWT_Charset_EastEuropean

East European

SWT_Charset_SouthEuropean

South European

SWT_Charset_NorthEuropean

North European

SWT_Charset_Cyrillic

Cyrillic

SWT_Charset_Arabic

Arabic

SWT_Charset_Greek

Greek

SWT_Charset_Hebrew

Hebrew

SWT_Charset_Turkish

Turkish

SWT_Charset_Nordic

Nordic

SWT_Charset_Thai

Thai

SWT_Charset_BalticRim

Baltic Rim

SWT_Charset_Celtic

Celtic

SWT_Charset_Euro

Euro

SWT_Charset_Romanian

Romanian

SWT_Charset_SimplifiedChinese

Simplified Chinese

SWT_Charset_TraditionalChinese

Traditional Chinese

SWT_Charset_Japanese

Japanese

SWT_Charset_Korean

Korean

SWT_Charset_Unicode

Unicode

SWT_Charset_ASCII

ASCII

SWT_InputMethods

Input Methods

 

Windows XPEclipse 2.1.1中输入这些代码:

System.out.println("Platform: " + SWT.getPlatform());

System.out.println("Version: " + SWT.getVersion());

这些代码会打印:

Platform: win32

Version: 2135

 

返回目录

转载于:https://www.cnblogs.com/ols/archive/2011/09/10/2173312.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值