public
class
MyMessages
extends
NLS {
private static final String BUNDLE_NAME = "com.hedalixin " ; // $NON-NLS-1$
public static String HELLO_WORLD;
public static String HELLO_SOMETHING;
static {
// initialize resource bundles
NLS.initializeMessages(BUNDLE_NAME, MyMessages. class );
}
}
private static final String BUNDLE_NAME = "com.hedalixin " ; // $NON-NLS-1$
public static String HELLO_WORLD;
public static String HELLO_SOMETHING;
static {
// initialize resource bundles
NLS.initializeMessages(BUNDLE_NAME, MyMessages. class );
}
}
资源文件MyMessages.property(上边的类名)的内容还是和以前一样:
HELLO_WORLD
=
Hello world
!
HELLO_SOMETHING = Hello { 0 } !
HELLO_SOMETHING = Hello { 0 } !
在程序里使用资源的方式如下:
System.out.println(MyMessages.HELLO_WORLD);
System.out.println(MyMessages.bind(MyMessages.HELLO_SOMETHING, " world " ));
System.out.println(MyMessages.bind(MyMessages.HELLO_SOMETHING, " world " ));
自动将工程的字符串导出到资源文件中:
右键工程名称>source>Externalize Strings...可自动完成以上步骤。