package labwork5; /** * The Canvas class is an implementation of the InteractiveElement interface representing a canvas in a GUI. * It can send and receive updates through a Mediator. */ public class Canvas implements InteractiveElement{ private String id; private Mediator mediator; /** * Constructs a Canvas with a specified ID and associated Mediator. * * @param id the unique identifier for the canvas * @param mediator the Mediator to communicate with */ public Canvas(String id, Mediator mediator) { this.id = id; this.mediator = mediator; } /** * Retrieves the ID of the canvas. * * @return the ID of the canvas */ public String getId() { return id; } /** * Sends an update message to the associated Mediator. * * @param updateMessage the update message to be sent */ @Override public void sendUpdate(String updateMessage) { mediator.update(this, updateMessage); } /** * Receives an update message from the Mediator and prints a message. * * @param updateMessage the received update message */ @Override public void receiveUpdate(String updateMessage) { System.out.printf("%s has has received an update with a message:\"%s\"\n", id, updateMessage); } }