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 42 public void paint( Graphics g ) { 43 44 // fill the first parallelogram: 45 g.setColor( Color.green ); 46 parallelogram1.fill( g ); 47 48 // fill the second parallelogram: 49 g.setColor( Color.yellow ); 50 parallelogram2.fill( g ); 51 52 } 53 54 }