有点急的,Graphics.drawString()怎么能画出转过码的GB2312中文的?(200分)

  • 主题发起人 空山新雨
  • 开始时间

空山新雨

Unregistered / Unconfirmed
GUEST, unregistred user!
[:(!]转了以后的中文可以在label,list中正常显示,但是在用Graphcis.drawString()的时候,画出来的是乱码,
转码代码如下:
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);
}
绘画代码如下:
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);
}
请问怎么可以画出正常的中文?多谢各位赐教。
 
你写的代码不全,绘画代码中有一句要不要都出错是怎么回事?出错还能编译吗?
问题可能不是出在你写的方法中,有可能是import或是其他实例变量出错了。
这样写出一部分代码没有办法看到问题出在哪。
 
> 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);
g.drawString(" " + new String(tipString.getBytes(), encoding) + ......
> }
 
"MingLiU"是繁体细明体,用其它字体试试。
 
字体是否支持?
您先试试英文就可以知道了
 
应该是字体问题,还是试试其它字体
 
顶部