1 /* 2 * File: DrawableRectangle.java 3 * 4 * A rectangle class 5 * 6 * Copyright: Northeast Parallel Architectures Center 7 * 8 */ 9 10 import java.awt.*; 11 12 public class DrawableRectangle extends DrawableObject { 13 14 public DrawableRectangle( 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 int x = Math.min( x1, x2 ); 20 int y = Math.min( y1, y2 ); 21 int w = Math.abs( x2 - x1 ); 22 int h = Math.abs( y2 - y1 ); 23 g.setColor( color ); 24 if ( fill ) { 25 g.fillRect( x, y, w, h ); 26 } else { 27 g.drawRect( x, y, w, h ); 28 } 29 } 30 31 public boolean contains( int some_x, int some_y ) { 32 int x = Math.min( x1, x2 ); 33 int y = Math.min( y1, y2 ); 34 int w = Math.abs( x2 - x1 ); 35 int h = Math.abs( y2 - y1 ); 36 Rectangle r = new Rectangle( x, y, w, h ); 37 return r.contains( some_x, some_y ); 38 } 39 40 }