高分相求 Graphics.drawString 的问题 你是要动态生成image吧,把页面编码设置成GBK试试。猜的。如果你能贴多谢代码可能会好些。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public void graphicsPie() { try { int width = 600; int height = 500; ChartGraphics chartGraphics = new ChartGraphics(); chartGraphics.image = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB); Graphics g = chartGraphics.image.getGraphics(); Graphics2D g2d = (Graphics2D) g; g.setColor(new Color(236, 233, 216)); g.fillRect(0, 0, width, height); g.setColor(Color.white); g.fillRect(11, 35, width - 21, height - 47); g.setColor(Color.white); g.fillRect(10, 35, width - 20, height - 46); g.setColor(Color.black); g.setFont(new Font("font", Font.PLAIN, 22)); g.drawString("Info", 15, 25); /////////// From Here ,have some difference //// int totalsales = 0; int book_sales[] = new int[5]; for (int i = 0; i < book_sales.length; i++) { book_sales[i] = 1 + (int) (Math.random() * 100); totalsales += book_sales[i]; } String book_title[] = {"python", "java", "c#", "peal", "php"}; Color color[] = new Color[5]; color[0] = new Color(99, 99, 0); color[1] = new Color(255, 169, 66); color[2] = new Color(33, 255, 66); color[3] = new Color(33, 0, 255); color[4] = new Color(255, 0, 66); g.setFont(new Font("font0", Font.BOLD, 30)); String teststr = "这是测试程序"; teststr = new String(teststr.getBytes("8859_1"), "GBK"); g.drawString(teststr, 50, 505); g.setFont(new Font("sansserif", Font.BOLD, 12)); g.drawString("SaleType", 400, 125); g.drawString("SaleNumber", 475, 125); g.drawString("Salepercent", 535, 125); g.setColor(Color.blue); g.drawRect(395,95,190,300); int ArcStartAngle = 30; int ArcEndAngle = 0; float scale; DecimalFormat twoDigits = new DecimalFormat("0.00"); // ******************* for (int i = 0; i < book_title.length; i++) { ArcEndAngle = (int) (book_sales[i] * 360/ (float)totalsales + 0.5); scale = (float)book_sales[i] / totalsales * 100; g.setColor(color[i]); if ( i < book_title.length - 1 ) { g.fillArc(15,95,350,300,ArcStartAngle,ArcEndAngle); }else { g.fillArc(30,93,350,300,ArcStartAngle,ArcEndAngle); } ArcStartAngle += ArcEndAngle; g.fillRect(400,155 + i * 50,12,12); g.setColor(Color.black); g.drawString(book_title[i], 420, 167 + i * 50); g.drawString("" + book_sales[i], 490, 167 + i * 50); g.drawString("" + twoDigits.format(scale) + "%", 540, 167 + i * 50); } g.dispose(); chartGraphics.createImage(PicFile); } catch(Exception e) { System.out.println("error = " + e.getMessage()); } } 问题又来了, g.setFont(new Font("宋体", Font.BOLD, 30)); g.drawString("统计分析", 50, 505);这段代码在windows 下编译并能正确执行,中文也是正确的。但假如在中文系统下编译好 class 后,放到 unix 的web服务器下执行,中文就又变成方框了. 是 unix 没有这字体,那该怎么做呢? 那你可能要认真设置unix上java环境的font.properties文件里的相关配置,设置到相应的字体。 java怎样实现把网页中选中的图片复制然后转为二进制放在剪贴板?给点提示思路即可 收集各类JAVA实现的设计模式代码 动态创建文本框问题 有人试过用JAVA开发INTEL等CPU平台的操作系统吗? 有关List和ArrayList之间的问题,不给答,俺就自杀 String 类型的值是否可以修改。 access里的一个字段最多能存储多少个汉字?我用备注类型300,不够啊!! 关于JMenuBar 一个关于Float[]的基本问题 关于Jbuilder中的LookAndFeel(系统显示风格的问题) 如何在Canvas里面画出一个JButton? 急求~~~~请高手进来啊~~~~
try {
int width = 600;
int height = 500; ChartGraphics chartGraphics = new ChartGraphics(); chartGraphics.image = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB); Graphics g = chartGraphics.image.getGraphics(); Graphics2D g2d = (Graphics2D) g; g.setColor(new Color(236, 233, 216));
g.fillRect(0, 0, width, height);
g.setColor(Color.white);
g.fillRect(11, 35, width - 21, height - 47);
g.setColor(Color.white);
g.fillRect(10, 35, width - 20, height - 46); g.setColor(Color.black);
g.setFont(new Font("font", Font.PLAIN, 22));
g.drawString("Info", 15, 25);
/////////// From Here ,have some difference //// int totalsales = 0;
int book_sales[] = new int[5];
for (int i = 0; i < book_sales.length; i++) {
book_sales[i] = 1 + (int) (Math.random() * 100);
totalsales += book_sales[i];
}
String book_title[] = {"python", "java", "c#", "peal", "php"};
Color color[] = new Color[5];
color[0] = new Color(99, 99, 0);
color[1] = new Color(255, 169, 66);
color[2] = new Color(33, 255, 66);
color[3] = new Color(33, 0, 255);
color[4] = new Color(255, 0, 66); g.setFont(new Font("font0", Font.BOLD, 30));
String teststr = "这是测试程序";
teststr = new String(teststr.getBytes("8859_1"), "GBK"); g.drawString(teststr, 50, 505); g.setFont(new Font("sansserif", Font.BOLD, 12));
g.drawString("SaleType", 400, 125);
g.drawString("SaleNumber", 475, 125);
g.drawString("Salepercent", 535, 125);
g.setColor(Color.blue);
g.drawRect(395,95,190,300); int ArcStartAngle = 30;
int ArcEndAngle = 0;
float scale;
DecimalFormat twoDigits = new DecimalFormat("0.00"); // *******************
for (int i = 0; i < book_title.length; i++) {
ArcEndAngle = (int) (book_sales[i] * 360/ (float)totalsales + 0.5);
scale = (float)book_sales[i] / totalsales * 100; g.setColor(color[i]);
if ( i < book_title.length - 1 ) {
g.fillArc(15,95,350,300,ArcStartAngle,ArcEndAngle);
}else {
g.fillArc(30,93,350,300,ArcStartAngle,ArcEndAngle);
}
ArcStartAngle += ArcEndAngle;
g.fillRect(400,155 + i * 50,12,12);
g.setColor(Color.black); g.drawString(book_title[i], 420, 167 + i * 50);
g.drawString("" + book_sales[i], 490, 167 + i * 50);
g.drawString("" + twoDigits.format(scale) + "%", 540, 167 + i * 50);
} g.dispose(); chartGraphics.createImage(PicFile); } catch(Exception e) {
System.out.println("error = " + e.getMessage());
}
}
g.drawString("统计分析", 50, 505);这段代码在windows 下编译并能正确执行,中文也是正确的。但假如在中文系统下编译好 class 后,放到 unix 的web服务器下执行,中文就又变成方框了. 是 unix 没有这字体,那该怎么做呢?
font.properties文件里的相关配置,
设置到相应的字体。