Our houses lose their roofs in unison. Windstorms do not typically work that way. Let’s change our program so that only the house that we click loses its roof. We will need to find the position of the mouse at the time it is pressed. Recall that the main Processing object keeps this information in the instance variables mouseX and mouseY. We will need to compare the values of these variables with the location of each House object in the window. The House object keeps track of its location in the currentX and currentY instance variables and keeps track of its size in the size instance variable. Since we are handling the mouse events in the main Processing object, we will need a way for the main Processing object to get the location and size information from the House objects. We do this by adding getters to the House object. Specifically, we will add the methods getX, getY, and getSize to the House objects. These methods will return the values of the House’s currentX, currentY, and size instance variables, respectively.
Figure 4.3.1 shows the changes to the code in the main Processing object, while Figure 4.3.3 shows the result of clicking one of the Houses with the mouse.