1 /* 2 * File: TriangleTest.java 3 * 4 * Drawing triangles 5 * 6 * Copyright: Northeast Parallel Architectures Center 7 * 8 */ 9 10 import java.applet.Applet; 11 import java.awt.Graphics; 12 import java.awt.Polygon; 13 14 public class TriangleTest extends Applet { 15 16 // create references to two polygons: 17 private Polygon p1, p2; 18 19 public void init() { 20 21 // instantiate a polygon object: 22 p1 = new Polygon(); 23 24 // add points to make a triangle: 25 p1.addPoint( 50, 25 ); 26 p1.addPoint( 75, 100 ); 27 p1.addPoint( 25, 100 ); 28 29 // instantiate a polygon object: 30 p2 = new Polygon(); 31 32 // add points to make another triangle: 33 p2.addPoint( 125, 25 ); 34 p2.addPoint( 175, 100 ); 35 p2.addPoint( 125, 100 ); 36 37 } 38 39 public void paint( Graphics g ) { 40 41 // draw a triangle: 42 g.drawPolygon( p1 ); 43 44 // draw another triangle: 45 g.fillPolygon( p2 ); 46 47 } 48 49 }