/* * File: TriangleTest2.java * * Drawing triangles * * Copyright: Northeast Parallel Architectures Center * */ import java.applet.Applet; import java.awt.Graphics; import java.awt.Polygon; import java.awt.Color; public class TriangleTest2 extends Applet { // create references to three polygons: private Polygon p1, p2, p3; 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 ); // instantiate a polygon object: p3 = new Polygon(); // add points to make a third triangle: p3.addPoint( 71, 125 ); p3.addPoint( 129, 125 ); p3.addPoint( 100, 175 ); } public void paint( Graphics g ) { // draw a triangle: g.drawPolygon( p1 ); // draw another triangle: g.fillPolygon( p2 ); // draw a third triangle: g.setColor( Color.red ); g.fillPolygon( p3 ); } }