1 /* 2 * File: ParallelogramTest.java 3 * 4 * Draw a parallelogram 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 ParallelogramTest extends Applet { 15 16 // create references to two parallelograms: 17 private Parallelogram parallelogram1, parallelogram2; 18 19 public void init() { 20 21 // top left-hand corner of the parallelogram: 22 int x = 125, y = 50; 23 // side lengths: 24 int side1 = 75, side2 = 50; 25 // included angle: 26 double alpha = 2 * Math.PI/3; 27 // rotation angle: 28 double theta = Math.PI; 29 30 // instantiate two parallelograms: 31 parallelogram1 = 32 new Parallelogram( x, y, side1, side2, alpha ); 33 parallelogram2 = 34 new Parallelogram( x, y, side1, side2, alpha, theta ); 35 /* 36 * here's another way to compute parallelogram2: 37 * parallelogram2 = parallelogram1.rotate( theta ); 38 * 39 */ 40 41 // color the parallelograms: 42 parallelogram1.setColor( Color.green ); 43 parallelogram2.setColor( Color.yellow ); 44 45 } 46 47 public void paint( Graphics g ) { 48 49 // fill the first parallelogram: 50 parallelogram1.fill( g ); 51 52 // fill the second parallelogram: 53 parallelogram2.fill( g ); 54 55 } 56 57 }