MouseMotionListener movePuck = new MouseMotionAdapter() {
public void mouseMoved(MouseEvent e)
{
int x = e.getX();
int y = getSize().height - puck.getSize().height;
puck.setLocation(x, y);
}
};
/* Create a row of targets, i.e. columns of boxes, along
* the top of the applet. Each target column contains
* between one and four boxes.
*/
for(int i = 0; i < targets.length; i++) {
int nBoxes = 1 + (int)(Math.random() * 4.0);
float boxHue = (float)i / (float)targets.length;
Color boxColor = Color.getHSBColor(boxHue, 0.5f, 0.85f);
TargetListener tl = new TargetListener(boxColor.brighter());
targets[i] = new ColumnOfBoxes(boxColor, nBoxes);
targets[i].addMouseListener(tl);
targets[i].addMouseMotionListener(tl);
add(targets[i]);
}
add(puck);
addMouseMotionListener(movePuck);