void MyMouseListener::mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { // Handle double-click event here e.consume(); } }
if (eventSource == button1) { // Handle button 1 click event here event.consume(); } else if (eventSource == button2) { // Handle button 2 click event here event.consume(); }In this example, two different button elements in a GUI application are handled in the same event listener function. When a button is clicked, the event listener checks which button was the event source, handles the event accordingly, and then calls the consume function to prevent other event listeners from handling the same event. These examples may use the package libraries for GUI applications in C++, such as Qt, wxWidgets, or JUCE.