applet的中文问题---急、急、急
如果把此applet单独运行java AppletTest那么输出的中文就是乱麻,
如果放在html页面中运行就会出现正确的中文。
但我需要的是单独运行applet,我该怎么转换呢?
import java.applet.*;
import java.awt.*;
import java.io.UnsupportedEncodingException;
public class AppletTest extends Applet{
public static void main(String args[]) {
Frame f = new Frame("DrawTest");
AppletTest a = new AppletTest();
f.add("Center", a);
f.setSize(300, 300);
f.setVisible(true);
}
public void paint(Graphics g) {
String str ="中文";
String s ="";
try {
//s = new String(str.getBytes("ISO-8859-1"),"GBK");
s = new String(str.getBytes(),"GB2312");
}
catch(UnsupportedEncodingException e) {
g.drawString(e.toString(),20,20);
}
g.drawString(s,10,10);
}
}