0

我需要对不同的图形对象(例如线条)应用不同的仿射变换,是否适合使用多个 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);
4

1 回答 1

1

不,因为它们根本不是两个不同的对象,它们是对同一个对象的两个引用。

于 2013-03-18T06:39:45.020 回答