Questions and Exercises: Writing Event Listeners
Use this lesson’s tables, the component how-to sections and the event listeners how-to sections to complete these questions and exercises.
Questions
1. What listener would you implement to be notified when a particular component has appeared on screen? What method tells you this information?
2. What listener would you implement to be notified when the user has finished editing a text field by pressing Enter? What listener would you implement to be notified as each character is typed into a text field? Note that you should not implement a general- purpose key listener, but a listener specific to text.
3. What listener would you implement to be notified when a spinner’s value has changed? How would you get the spinner’s new value?
4. The default behavior for the focus subsystem is to consume the focus traversal keys, such as Tab and Shift Tab. Say you want to prevent this from happening in one of your application’s components. How would you accomplish this?
Exercises
1. Take the Beeper.java
2. Take the Beeper.java