1 /* 2 * File: Quadrilateral.java 3 * 4 * Quadrilateral class 5 * 6 * Copyright: Northeast Parallel Architectures Center 7 * 8 */ 9 10 import java.awt.Polygon; 11 import java.awt.Graphics; 12 13 // A quadrilateral is a polygon with four sides: 14 public class Quadrilateral extends Polygon { 15 16 // Quadrilateral constructor #1: 17 public Quadrilateral() { 18 // invoke the constructor of the superclass Polygon: 19 super(); 20 } 21 22 // Quadrilateral constructor #2: 23 public Quadrilateral( int x1, int y1, 24 int x2, int y2, 25 int x3, int y3, 26 int x4, int y4 ) { 27 28 // invoke the constructor of the superclass Polygon: 29 super(); 30 31 // the 'this' reference is optional: 32 this.addPoint( x1, y1 ); 33 this.addPoint( x2, y2 ); 34 this.addPoint( x3, y3 ); 35 this.addPoint( x4, y4 ); 36 37 } 38 39 // Instance methods: 40 public void draw( Graphics g ) { 41 g.drawPolygon( this ); 42 } 43 public void fill( Graphics g ) { 44 g.fillPolygon( this ); 45 } 46 47 }