Chapter 14


Chapter 13

1. 

What is the base class for all events?

 - java.util.eventobject is the base class for all events.

2. 

What is the base class for all listeners?

 - java.util.eventobject is the base class for all events.

3. 

What are the six steps to handing an event?

image from book

4. 

Explain the difference between a low-level event and a semantic event.

image from book

5. 

Why is it preferable to listen for semantic events?

image from book

6. 

What methods does the java.util.EventObject class define?

 - java.util.eventobject defines the one method getsource() which returns the source of the event

7. 

What methods does the java.util.EventListener interface declare?

 - java.util.eventlistener declares no methods!

8. 

What are the benefits and drawbacks to using the “Existing Class” approach to handling an event?

image from book

9. 

What is an inner class? What are the benefits to using an inner class to handle an event?

image from book

10. 

What is an anonymous class? What are the benefits to using an anonymous class to handle an event?

image from book

11. 

What is an adapter? Why might you use an adapter to handle an event?

image from book

Answers

1. 

- java.util.EventObject is the base class for all events.

2. 

- java.util.EventObject is the base class for all events.

3. 

- The six steps to handling events are:

  1. Determine the desired application behavior from the user’s perspective.

  2. Determine the component that will be the source of the event.

  3. Determine and become familiar with the event type of interest making sure that the source component can respond to it.

  4. Become familiar with the associated event listener.

  5. Choose a design approach and implement the listener.

  6. Register the listener with the source component.

4. 

- Low-level events represent window-system occurrences or low-level input, such as the pressing of a mouse but-ton or the typing of the letter ‘a’. Semantic events include anything else like the selection of a menu or the resizing of a window, and they may or may not be triggered by user input.

5. 

- Generally speaking, semantic events are the ones to pay attention to because they represent more “meaningful” concepts.

6. 

- java.util.EventObject defines the one method getSource() which returns the source of the event

7. 

- java.util.EventListener declares no methods!

8. 

- Using an existing class is perhaps the most efficient way to approach the implementation of an event listener as there is always a bit of overhead with the loading of new class type. However, it can lead to long method definitions, and it tends to clump lots of code together that might be more elegantly expressed separately.

9. 

- An inner class is a class defined within the scope of another class. Many times, an EventListener class needs access to fields or methods of an object that would best be left private or protected. If, as is often the case, that listener will only ever be created or referenced by that same object, then it may be preferable to declare the listener as an inner class of the object, thereby giving it automatic access to all the object’s fields and simplifying access issues.

10. 

- An anonymous class is a class that cannot be referred to - not because of visibility issues but because it is never assigned a name. Use of an anonymous class is a concise and frequently appropriate design approach because the listener instance is defined in the very same place as it is used.

11. 

- Sometimes the situation arises where you need to implement an EventListener interface but are only interested in some - not all of its methods. An adapter class implements all an interface’s methods with do-nothing methods thereby providing you the option of extending it and only overriding the methods in which you are interested. Adapters are useful mostly when you are creating anonymous listener instances and want to keep the code succinct for readability purposes.




Java For Artists(c) The Art, Philosophy, and Science of Object-Oriented Programming
Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504052
EAN: 2147483647
Year: 2007
Pages: 452

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