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 // create a reference to a rectangle: 17 private Rectangle rectangle; 18 19 // rectangle parameters: 20 private int x, y, w, h; 21 22 // constant number of rotations: 23 private final int N = 8; 24 25 // rotation angle: 26 private final double angle = 2 * Math.PI/N; 27 28 public void init() { 29 30 // top left-hand corner of the rectangle: 31 x = 100; y = 100; 32 // width and height of the rectangle: 33 w = 75; h = 50; 34 35 } 36 37 public void paint( Graphics g ) { 38 39 g.setColor( Color.red ); 40 41 double theta = 0; 42 for ( int i = 0; i < N; i++ ) { 43 theta += angle; 44 rectangle = new Rectangle( x, y, w, h, theta ); 45 rectangle.draw( g ); 46 } 47 48 } 49 50 }