Questions and Exercises

 <  Day Day Up  >  

Use this chapter's tables, the how-to sections for components (Chapter 7), and if necessary the how-to sections for event listeners (Chapter 10) 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 example (discussed on page 108) and add a text field. Implement it so that when the user has finishing entering data, the system beeps.

2:

Take the Beeper example and add a selectable component that allows the user to enter a number from 1 to 10. For example, you can use a combo box, a set of radio buttons , or a spinner. Implement it so that when the user has selected the number, the system beeps that many times.


Answers

You can find answers to the Questions and Exercises online:

http://java.sun.com/docs/books/tutorial/uiswing/QandE/answers.html

 <  Day Day Up  >  


JFC Swing Tutorial, The. A Guide to Constructing GUIs
The JFC Swing Tutorial: A Guide to Constructing GUIs (2nd Edition)
ISBN: 0201914670
EAN: 2147483647
Year: 2004
Pages: 171

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net