PixelRectangle demonstrates how to draw an object using the AWT drawing API. @author Wolfgang Christian, Jan Tobochnik, Harvey Gould @version 1.0 05/16/05
| 16 | * @version 1.0 05/16/05 |
| 17 | */ |
| 18 | public class PixelRectangle implements Drawable { |
| 19 | int left, top; // position of rectangle in pixels |
| 20 | int width, height; // size of rectangle in pixels |
| 21 | |
| 22 | /** |
| 23 | * Constructs a PixelRectangle with position and dimensions values given in pixel coordinates. |
| 24 | * |
| 25 | * @param left int |
| 26 | * @param top int |
| 27 | * @param width int |
| 28 | * @param height int |
| 29 | */ |
| 30 | PixelRectangle(int left, int top, int width, int height) { |
| 31 | this.left = left; // location of left edge |
| 32 | this.top = top; // location of top edge |
| 33 | this.width = width; |
| 34 | this.height = height; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Draws this rectangle using the AWT drawing API. |
| 39 | * Required to implement the Drawable interface. |
| 40 | * |
| 41 | * @param panel DrawingPanel |
| 42 | * @param g Graphics |
| 43 | */ |
| 44 | @Override |
| 45 | public void draw(DrawingPanel panel, Graphics g) { |
| 46 | // this method implements the Drawable interface |
| 47 | g.setColor(Color.RED); // set drawing color to red |
| 48 | g.fillRect(left, top, width, height); // draws rectangle |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | /* |
| 53 | * Open Source Physics software is free software; you can redistribute |
nothing calls this directly
no outgoing calls
no test coverage detected