1 /* File: mPoint.java */ 2 3 import java.awt.*; 4 5 public abstract class mPoint 6 { 7 // Instance variables: 8 protected int x, y; // location of moving point 9 protected int dx, dy; // displacement of moving point 10 protected Color color; // color of moving point 11 12 // Constructor: 13 public mPoint( int new_x, int new_y ) 14 { 15 x = new_x; y = new_y; 16 dx = 1; dy = 1; 17 color = Color.black; 18 } 19 20 // Accessors and mutators: 21 public int getX() { return x; } 22 public int getY() { return y; } 23 public void setPoint( int new_x, int new_y ) 24 { x = new_x; y = new_y; 25 } 26 public void setDelta( int new_dx, int new_dy ) 27 { dx = new_dx; dy = new_dy; 28 } 29 public Color getColor() { return color; } 30 public void setColor( Color new_color ) 31 { color = new_color; 32 } 33 34 // Class method: 35 public void move() 36 { 37 x += dx; y += dy; 38 } 39 40 // Class methods to be implemented by subclasses: 41 public abstract void paint( Graphics g ); 42 public abstract void checkBoundary( Rectangle rect ); 43 public abstract boolean isInside( int some_x, int some_y ); 44 45 } // end of mPoint class 46