MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / draw

Method draw

src/csm/ch03/WorldRectangle.java:44–54  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

42 * @param g Graphics
43 */
44 @Override
45public 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/*

Callers

nothing calls this directly

Calls 6

getXPixPerUnitMethod · 0.80
getYPixPerUnitMethod · 0.80
setColorMethod · 0.45
xToPixMethod · 0.45
yToPixMethod · 0.45
fillRectMethod · 0.45

Tested by

no test coverage detected