Threads2 (other files are same as before): Row.java

import java.awt.*;
import java.util.concurrent.*;

/**
 * This is now just an abstract base class
 * for SupplyRow and ConsumerRow
 */
abstract public class Row { //*1 Abstract base class, mainly for drawing
    protected Canvas canvas;
    protected Rectangle loc;
    protected CopyOnWriteArrayList<Box> boxes = new CopyOnWriteArrayList<Box> (); //*1

    public Row (Rectangle loc, Canvas canvas) {
	this.loc = loc;
	this.canvas = canvas;
    }

    public void draw (Graphics g) { //*1
	Graphics2D g2 = (Graphics2D) g;

	g2.draw (loc); //*1

	// We tell each Box where to draw itself
	int boxsize = loc.height-2*5;
	Rectangle boxloc = new Rectangle (loc.x+10, loc.y+5,
					  boxsize, boxsize);

	// Draw each of our Box's
	for (Box b: boxes) { //*1
	    b.draw (g, boxloc); //*1
	    boxloc.x = boxloc.x + boxsize + 10;
	}
    }
}
[download file]