/* * File: TriangleTest.java * * Drawing triangles * * Copyright: Northeast Parallel Architectures Center * */ import java.applet.Applet; import java.awt.Graphics; import java.awt.Polygon; public class TriangleTest extends Applet { // create references to two polygons: private Polygon p1, p2; public void init() { // instantiate a polygon object: p1 = new Polygon(); // add points to make a triangle: p1.addPoint( 50, 25 ); p1.addPoint( 75, 100 ); p1.addPoint( 25, 100 ); // instantiate a polygon object: p2 = new Polygon(); // add points to make another triangle: p2.addPoint( 125, 25 ); p2.addPoint( 175, 100 ); p2.addPoint( 125, 100 ); } public void paint( Graphics g ) { // draw a triangle: g.drawPolygon( p1 ); // draw another triangle: g.fillPolygon( p2 ); } }