solving the rotating rectangles problem in java swing