1 /* 2 * File: DrawablePolygonTest3.java 3 * 4 * Draw some regular polygons 5 * 6 * Copyright: Northeast Parallel Architectures Center 7 * 8 */ 9 10 import java.applet.Applet; 11 import java.awt.Graphics; 12 import java.awt.Point; 13 14 public class DrawablePolygonTest3 extends Applet { 15 16 // create a reference to a polygon: 17 private DrawablePolygon polygon; 18 19 private int r; 20 private int border; 21 22 public void init() { 23 24 // radius of regular polygons: 25 r = 50; 26 // space between polygons: 27 border = 20; 28 29 } 30 31 public void paint( Graphics g ) { 32 33 // anchor point of each polygon: 34 int x, y; 35 36 // initial degree: 37 int n = 3; 38 39 // draw a 3x3 grid of regular polygons: 40 y = -r; 41 for ( int i = 0; i < 3; i++ ) { 42 x = -r; y += border + 2*r; 43 for ( int j = 0; j < 3; j++ ) { 44 x += border + 2*r; 45 polygon = new DrawablePolygon( x, y, r, n++ ); 46 polygon.fill( g ); 47 } 48 } 49 50 } 51 52 }