Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Mastering Java: The Ultimate Quiz for 'Thinking in Java'. Dive deep into Java with multiple-choice questions. Challenge yourself with quiz questions designed to test and improve your understanding of the 'Thinking in Java' book. Get ready for your exam!

Practice this question and more.


How do you add a listener to respond to SWT button press events?

  1. addSelectionListener

  2. addListener

  3. addButtonListener

  4. addPressListener

The correct answer is: addSelectionListener

SWT button press event listeners are added using the addSelectionListener method. The addListener method is not specific to button press events and can be used to add listeners for various types of events. The addButtonListener and addPressListener methods do not exist in the SWT library and cannot be used to add listeners. Therefore, the correct way to add a listener for a SWT button press event is by using the addSelectionListener method.