This is done by getting the global function mousePressed() to call a function clicked() inside every object. Each object then checks if the click was actually inside it.