1 /* File: mTriangle.java */ 2 3 import java.awt.*; 4 5 public class mTriangle extends mRectangle 6 { 7 public mTriangle( int new_x, int new_y, int new_w, int new_h ) 8 { 9 // Call mRectangle's constructor: 10 super( new_x, new_y, new_w, new_h ); 11 } 12 13 // Override mRectangle.paint( Graphics ): 14 public void paint( Graphics g ) 15 { 16 g.setColor( color ); 17 // Compute vertices and draw triangle: 18 int xvalues[] = { x, x + w, x + w/2 }; 19 int yvalues[] = { y + h, y + h, y }; 20 g.fillPolygon( xvalues, yvalues, 3 ); 21 } 22 23 }