Hello,
I tried to make a program where two rectangles are rotating around their centers.
But the second of them is orbiting around the first one.
Code:
private void drawRect(int x, int y, int width, int height, double angle,
Graphics2D g2) {
AffineTransform old = g2.getTransform();
AffineTransform af = new AffineTransform();
af.rotate(Math.toRadians(angle), (double) width / 2.0,
(double) height / 2.0);
g2.transform(af);
g2.fillRect(x, y, width, height);
g2.transform(old);
}
and then:
g2.setColor(Color.BLUE);
drawRect(0,0,100,100,angle,g2);
g2.setColor(Color.RED);
drawRect(200,200,50,100,angle2,g2);
angle+=0.3;
angle2++;
I tried using g2.rotate first,but it gave me the same problem,so I tried using AffineTransform.Of course,nothing changed...
Screenshot is attached.
Help!!!
Thanks,
MatejaS