有点急的,Graphics.drawString()怎么能画出转过码的GB2312中文的?
ksxy 2002-07-24 10:08:11 转码代码如下:
String encoding = "GB2312";
try {
int curLength = 0;
StringBuffer buffer = new StringBuffer();
char[] buf = new char[1024];
InputStreamReader isr = new InputStreamReader(typeFile.openStream(), encoding);
while (curLength != -1) {
Arrays.fill(buf, '\0');
curLength = isr.read(buf, 0, buf.length);
buffer.append(buf);
}
return new BufferedReader(new StringReader(
new String(buffer.toString().getBytes(encoding), "ISO8859_1")));
} catch (UnsupportedEncodingException e) {
throw new ConfigException(this, encoding + " not supported", "", 0);
}
转了以后的中文可以在label,list中正常显示,但是在用Graphcis.drawString()的时候,画出来的是乱码,
public void paint(Graphics g) {
g.setColor(borderColor);
g.setFont(new Font("MingLiU", Font.PLAIN, 12)); //这一句要不要都错
g.drawRect(0, 0, this.getWidth() - 1, this.getHeight() - 1);
g.drawString(" " + tipString + " ", 0, this.getHeight() - 4);
}
请问怎么可以画出正常的中文?多谢各位赐教。