// ColorCmd.java // Command class to perform a color-change command. // Written by THC for CS 5 Lab Assignment 3. import java.awt.*; public class ColorCmd extends Command { // When the mouse is clicked, find the frontmost Shape in the drawing // that contains the mouse position. If there is such a Shape, then // have it change its color. // By the time the mouse is clicked for a color-changing command, the // drawing's default color has already been updated. So we can use // that to determine what color to set the Shape. public void executeClick(Point p, Drawing dwg) { // Find the frontmost Shape containing p. Shape s = dwg.getFrontmostContainer(p); if (s != null) // was there a Shape containing p? s.setColor(dwg.getColor()); // yes, change its color } }