我需要对不同的图形对象(例如线条)应用不同的仿射变换,是否适合使用多个 Graphics2D 对象来执行此任务?代码:
Graphics2D g2seconds = (Graphics2D) g; // g - Graphics class
Graphics2D g2minutes = (Graphics2D) g;
AffineTransform atseconds =
AffineTransform.getRotateInstance(Math.PI/30*s, 0, 0);//s = Time in seconds
AffineTransform atminutes =
AffineTransform.getRotateInstance(Math.PI/30*m, 0, 0);//m = Time in minutes
g2seconds.setTransform(atseconds);
g2seconds.drawLine(0, 0, 10, 10);
g2minutes .setTransform(atminutes);
g2minutes .drawLine(0, 0, 10, 10);