public void rotateText(Graphics g, String s, double angle, int x, int y)
{
Graphics2D g2d = (Graphics2D)g;
// Move the origin to the (x,y)
g2d.translate(x, y);
// Rotate the angle
g2d.rotate(Math.PI*(angle/-180));
// Draw text
g2d.drawString(s, 0, 0);
//Restore moving and rotating
g2d.rotate(-Math.PI*(angle/-180));
g2d.translate(-x,-y);
}
我刚才试了第一位老兄的程序
还是有问题
不过如果我在循环体内加上一条比如System.out,println(s);
运行的时候就很慢
但是在资源管理器中看只用了22多M内存
去掉的话,用了60多M
我的循环是400多次
public void rotateText(Graphics g, String s, double angle, int x, int y)
{
Graphics2D g2d = (Graphics2D)g;
// Move the origin to the (x,y)
g2d.translate(x, y);
// Rotate the angle
g2d.rotate(Math.PI*(angle/-180));
~~~~~~~~~~~~~~~~~~这个地方应该是-Math.PI*angle/180;
// Draw text
g2d.drawString(s, 0, 0);
//Restore moving and rotating
g2d.rotate(-Math.PI*(angle/-180));
g2d.translate(-x,-y);
}