import java.awt.Canvas; import java.awt.Color; import java.awt.Graphics; import java.util.ArrayList; /** * Draws a collection of DrawablePolygons. */ public class Drawing extends Canvas { private ArrayList list; /** * Constructs a drawing of given size. * * @param width the width in pixels * @param height the height in pixels */ public Drawing(int width, int height) { setSize(width, height); setBackground(Color.WHITE); list = new ArrayList(); } /** * Adds a new actor to the drawing. * * @param dp the object to add */ public void add(DrawablePolygon dp) { list.add(dp); } /** * Draws all the actors on the canvas. * * @param g graphics context */ @Override public void paint(Graphics g) { for (DrawablePolygon dp : list) { dp.draw(g); } } /** * Calls the step method of each actor and updates the drawing. */ public void step() { for (DrawablePolygon dp : list) { dp.step(); } repaint(); } }