有点急的,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);
}

请问怎么可以画出正常的中文?多谢各位赐教。
...全文
68 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧