1  /*
  2   *  File:  RectangleTest.java
  3   *
  4   *  Rotate a rectangle
  5   *
  6   *  Copyright:  Northeast Parallel Architectures Center
  7   *  
  8   */
  9  
 10  import java.applet.Applet;
 11  import java.awt.Graphics;
 12  import java.awt.Color;
 13  
 14  public class RectangleTest extends Applet {
 15  
 16     // constant number of rotations:
 17     private final int N = 8;
 18     
 19     // rotation angle:
 20     private final double angle = 2 * Math.PI/N;
 21        
 22     // create an array of rectangles:
 23     private Rectangle rectangle[] = new Rectangle[ N ];
 24     
 25     public void init() {
 26     
 27        // top left-hand corner of the rectangle:
 28        int x = 100, y = 100;
 29        // width and height of the rectangle:
 30        int w =  75, h =  50;
 31        
 32        // initialize rectangle array:
 33        double theta = 0;
 34        for ( int i = 0; i < N; i++ ) {
 35           theta += angle;
 36           rectangle[i] = new Rectangle( x, y, w, h, theta );
 37        }
 38  
 39     }
 40     
 41     public void paint( Graphics g ) {
 42  
 43        g.setColor( Color.red );
 44  
 45        // draw the rectangles:
 46        for ( int i = 0; i < N; i++ ) {
 47           rectangle[i].draw( g );
 48        }
 49  
 50     }
 51     
 52  }