Draws this rectangle using a drawing panel's world coordinates. Required to implement the Drawable interface. @param panel DrawingPanel @param g Graphics
(DrawingPanel panel, Graphics g)
| 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 | // convert from world to pixel coordinates |
| 49 | int leftPixels = panel.xToPix(left); |
| 50 | int topPixels = panel.yToPix(top); |
| 51 | int widthPixels = (int) (panel.getXPixPerUnit()*width); |
| 52 | int heightPixels = (int) (panel.getYPixPerUnit()*height); |
| 53 | g.fillRect(leftPixels, topPixels, widthPixels, heightPixels); // draws rectangle |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /* |
nothing calls this directly
no test coverage detected