/*
* ResourceTest.java
* Copyright Yoon Kyung Koo. All rights reserved.
*/
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
/**
* ResourceTest class
* tests ResourceBundle/PropertyResource classes
*
* NOTE ------------------------------------------------------------------
* 1. NOTE that you should make ListResourceBundle derived class public !!!
* 2. ResourceBundle.getBundle() methods first search bundle classes
* and later search properties files
* 3. always compile with option -encoding EUC_KR
* 4. JDK 1.2 on Digital Unix doens't work correctly in Korean locale.
* (default encoding of System.in and System.out is wrong ... not EUC_KR but ASCII7)
* 5. when you get resource bundles from resource classes, you need not handle KSC strings,
* but if you get them from properties files, you should handle that bytes into KSC strings.
* for example,
* try {
* String ok =
* new String(bundle.getString("OKKey").getBytes("8859_1"), "EUC_KR");
* } catch (java.io.UnsupportedEncodingException uee) {
* out.println(uee.toString());
* }
*
* @version @(#)ResourceTest.java 0.01 1999-08-31
* @author Yoon Kyung Koo
*/
public class ResourceTest extends Frame {
public static void main(String[] args) {
Locale.setDefault(Locale.KOREAN);
ResourceTest frame = new ResourceTest("Resource Test");
frame.setSize(500, 500);
frame.setVisible(true);
}
ResourceTest(String title) {
super(title);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
dispose();
System.exit(0);
}
});
}
public void paint(Graphics g) {
PrintWriter out = new PrintWriter(System.out, true);
String enc = new OutputStreamWriter(System.out).getEncoding();
System.out.println("default encoding = " + enc);
// PrintStream out = System.out;
ResourceBundle bundle =
ResourceBundle.getBundle("MyResource", Locale.KOREAN);
out.println("Is bundle an instance of ListResourceBundle? "
+ (bundle instanceof java.util.ListResourceBundle));
/*
out.println("Is bundle an instance of MyResource? "
+ (bundle instanceof MyResource));
out.println("Is bundle an instance of MyResource_ko? "
+ (bundle instanceof MyResource_ko));
out.println("Is bundle an instance of MyResource_ko_KR? "
+ (bundle instanceof MyResource_ko_KR));
*/
String ok = bundle.getString("OKKey");
// only when read from properties file this is necessary
// /*
try {
ok = new String(ok.getBytes("8859_1"), "EUC_KR");
} catch (java.io.UnsupportedEncodingException uee) { out.println(uee.toString()); }
// */
g.drawString(ok, 100, 100);
out.println("OK resource is "+ok);
String cancel = bundle.getString("CancelKey");
// only when read from properties file this is necessary
// /*
try {
cancel = new String(cancel.getBytes("8859_1"), "EUC_KR");
} catch (java.io.UnsupportedEncodingException uee) { out.println(uee.toString()); }
// */
g.drawString(cancel, 300, 100);
out.println("CANCEL resource is "+cancel);
}
}