Previous | Home | Next |
Q.1 The event delegation model, introduced in release 1.1 of the JDK, is fully compatible with the event model.
(a). True
(b). Flase
Answer: (b). Flase
Q.2 A component subclass that has executed enableEvents( ) to enable processing of a certain kind of event cannot also use an adapter as a listener for the same kind of event.
(a). True
(b). Flase
Answer: (b). Flase
Answer: The java.util.eventObject class is the highest-level class in the event-delegation hierarchy.
Q.4 What interface is extended by AWT event listeners?
Answer: All AWT event listeners extend the java.util.EventListener interface.
Q.5 What class is the top of the AWT event hierarchy?
Answer: The java.awt.AWTEvent class is the highest-level class in the AWT event class hierarchy.
Answer: The ActionEvent event is generated as the result of the clicking of a button.
Q.7 What is the relationship between an event-listener interface and an event-adapter class?
Answer: An event-listener interface defines the methods that must be implemented by an event handler for a particular kind of event. An event adapter provides a default implementation of an event-listener interface.
Q.8 In which package are most of the AWT events that support the event-delegation model defined?
Answer: Most of the AWT–related events of the event-delegation model are defined in the java.awt.event package. The AWTEvent class is defined in the java.awt package.
Q.9 What is the advantage of the event-delegation model over the earlier event-inheritance model?
Answer: The event-delegation has two advantages over the event-inheritance model. They are :
- It enables event handling by objects other than the ones that generate the events. This allows a clean separation between a component’s design and its use.
- It performs much better in applications where many events are generated. This performance improvement is due to the fact that the event-delegation model does not have to repeatedly process unhandled events, as is the case of the event-inheritance model.
Answer: The enableEvents( ) method is used to enable an event for a particular object.
(a). The event-inheritance model has replaced the event-delegation model.
(b). The event-inheritance model is more efficient than the event-delegation model.
(c). The event-delegation model uses event listeners to define the methods of event-handling classes.
(d). The event-delegation model uses the handleEvent( ) method to support event handling.
Answer: (c).The event-delegation model uses event listeners to define the methods of event-handling classes.
(a). java.util.EventListener
(b). java.util.EventObject
(c). java.awt.AWTEvent
(d). java.awt.event.AWTEvent
Answer: (b). java.util.EventObject
Q.13 When two or more objects are added as listeners for the same event, which listener is first invoked to handle the event?
(a). The first object that was added as listener.
(b). The last object that was added as listener.
(c). There is no way to determine which listener will be invoked first.
(d). It is impossible to have more than one listener for a given event.
Answer: (c). There is no way to determine which listener will be invoked first.
(a). Buttons
(b). Labels
(c). Check boxes
(d). Windows
Answer: (a). Buttons
(a). A TextField object may generate an ActionEvent.
(b). A TextArea object may generate an ActionEvent.
(c). A Button object may generate an ActionEvent.
(d). A MenuItem object may generate an ActionEvent.
Answer:
(a). A TextField object may generate an ActionEvent.
(c). A Button object may generate an ActionEvent.
(d). A MenuItem object may generate an ActionEvent.
(a). The MouseListener interface defines methods for handling mouse clicks.
(b). The MouseMotionListener interface defines methods for handling mouse clicks.
(c). The MouseClickListener interface defines methods for handling mouse clicks.
(d). The ActionListener interface defines methods for handling the clicking of a button.
Answer:
(a). The MouseListener interface defines methods for handling mouse clicks.
(d). The ActionListener interface defines methods for handling the clicking of a button.
Q.17 Suppose that you want to have an object eh handle the TextEvent of a TextArea object t. How should you add eh as the event handler for t?
(a). addTextListener(eh);
(b). addTextListener(t);
(c). addTextListener(eh.t);
(d). addTextListener(t,eh);
Answer: (a). addTextListener(eh);
(a). Override the object’s handleEvent( ) method.
(b). Add one or more event listeners to handle the events.
(c). Have the object override its processEvent( ) methods.
(d). Have the object override its dispatchEvent( ) methods.
Answer: (b). Add one or more event listeners to handle the events.
(a). A component may handle its own events by adding itself as an event listener.
(b). A component may handle its own events by overriding its event-dispatching method.
(c). A component may not handle oits own events.
(d). A component may handle its own events only if it implements the handleEvent( ) method.
Answer:
(a). A component may handle its own events by adding itself as an event listener.
(b). A component may handle its own events by overriding its event-dispatching method.
Answer: The AWT provides two types of events. They are :
Low-level event: A low-level event is the one that represents a low-level input or window-system occurrence on a visual component on the screen.
Semantic event: Semantic event is defined at a higher-level to encapsulate the semantics of a user interface component’s model.
Answer: source.
Q.22 The event listener corresponding to handling keyboard events is the _________ .
Answer: KeyListener.
Answer: MouseListener and MouseMotionListener.
(a). mousePressed(MouseEvent e){}
(b). MousePressed(MouseClick e){}
(c). functionKey(KeyPress k){}
(d). componentAdded(ContainerEvent e){}
Answer:
(a). mousePressed(MouseEvent e){}
(d). componentAdded(ContainerEvent e){}
(a). A component may have only one event listener attached at a time
(b). An event listener may be removed from a component
(c). The ActionListener interface has no corresponding Adapter class
(d). The processing of an event listener requires a try/catch block
Answer:
(b). An event listener may be removed from a component
(c). The ActionListener interface has no corresponding Adapter class
Previous | Home | Next |