1 /* 2 * File: DrawableLine.java 3 * 4 * A line class 5 * 6 * Copyright: Northeast Parallel Architectures Center 7 * 8 */ 9 10 import java.awt.*; 11 12 public class DrawableLine extends DrawableObject { 13 14 public DrawableLine( int new_x1, int new_y1, int new_x2, int new_y2 ) { 15 super( new_x1, new_y1, new_x2, new_y2 ); 16 } 17 18 public void paint( Graphics g ) { 19 g.drawLine( x1, y1, x2, y2 ); 20 } 21 22 // Return true if a point (x,y) lies on the line segment: 23 public boolean contains( int x, int y ) { 24 return ( x >= Math.min( x1, x2 ) && x <= Math.max( x1, x2 ) && 25 y >= Math.min( y1, y2 ) && y <= Math.max( y1, y2 ) && 26 (y - y2) * (x2 - x1) == (y2 - y1) * (x - x2) ); 27 } 28 29 } 30