Source of MyLine.java


  1: // Fig. 8.21: MyLine.java
  2: // Declaration of class MyLine.
  3: import java.awt.Color;
  4: import java.awt.Graphics;
  5: 
  6: public class MyLine
  7: {
  8:    private int x1; // x coordinate of first endpoint
  9:    private int y1; // y coordinate of first endpoint
 10:    private int x2; // x coordinate of second endpoint
 11:    private int y2; // y coordinate of second endpoint
 12:    private Color myColor; // color of this shape
 13: 
 14:    // constructor with input values
 15:    public MyLine( int x1, int y1, int x2, int y2, Color color )
 16:    {
 17:       this.x1 = x1; // set x coordinate of first endpoint
 18:       this.y1 = y1; // set y coordinate of first endpoint
 19:       this.x2 = x2; // set x coordinate of second endpoint
 20:       this.y2 = y2; // set y coordinate of second endpoint
 21:       myColor = color; // set the color
 22:    } // end MyLine constructor
 23:    
 24:    // Actually draws the line
 25:    public void draw( Graphics g )
 26:    {
 27:       g.setColor( myColor );
 28:       g.drawLine( x1, y1, x2, y2 );
 29:    } // end method draw
 30: } // end class MyLine
 31: 
 32: 
 33: /**************************************************************************
 34:  * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *
 35:  * Pearson Education, Inc. All Rights Reserved.                           *
 36:  *                                                                        *
 37:  * DISCLAIMER: The authors and publisher of this book have used their     *
 38:  * best efforts in preparing the book. These efforts include the          *
 39:  * development, research, and testing of the theories and programs        *
 40:  * to determine their effectiveness. The authors and publisher make       *
 41:  * no warranty of any kind, expressed or implied, with regard to these    *
 42:  * programs or to the documentation contained in these books. The authors *
 43:  * and publisher shall not be liable in any event for incidental or       *
 44:  * consequential damages in connection with, or arising out of, the       *
 45:  * furnishing, performance, or use of these programs.                     *
 46:  *************************************************************************/