Java 16 [applets, classes, java awt, windows]

EVENT HANDLING

The event delegation model, introduced in release 1.1 of the JDK, is fully compatible with the event model.
True
False
Ans : b.

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.
True
False
Ans : b.

What is the highest-level event class of the event-delegation model?
Ans : The java.util.eventObject class is the highest-level class in the event-delegation hierarchy.

What interface is extended by AWT event listeners?
Ans : All AWT event listeners extend the java.util.EventListener interface.

What class is the top of the AWT event hierarchy?
Ans : The java.awt.AWTEvent class is the highest-level class in the AWT event class hierarchy.

What event results from the clicking of a button?
Ans : The ActionEvent event is generated as the result of the clicking of a button.

What is the relationship between an event-listener interface and an event-adapter class?
Ans : 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.

In which package are most of the AWT events that support the event-delegation model defined?
Ans : 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.

What is the advantage of the event-delegation model over the earlier event-inheritance model?
Ans : 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.

What is the purpose of the enableEvents( ) method?
Ans :The enableEvents( ) method is used to enable an event for a particular object.

Which of the following are true?
The event-inheritance model has replaced the event-delegation model.
The event-inheritance model is more efficient than the event-delegation model.
The event-delegation model uses event listeners to define the methods of event-handling classes.
The event-delegation model uses the handleEvent( ) method to support event handling.
Ans : c.

Which of the following is the highest class in the event-delegation model?
java.util.EventListener
java.util.EventObject
java.awt.AWTEvent
java.awt.event.AWTEvent
Ans : b.

When two or more objects are added as listeners for the same event, which listener is first invoked to handle the event?
The first object that was added as listener.
The last object that was added as listener.
There is no way to determine which listener will be invoked first.
It is impossible to have more than one listener for a given event.
Ans : c.

Which of the following components generate action events?
Buttons
Labels
Check boxes
Windows
Ans : a.

Which of the following are true?
A TextField object may generate an ActionEvent.
A TextArea object may generate an ActionEvent.
A Button object may generate an ActionEvent.
A MenuItem object may generate an ActionEvent.
Ans : a,c and d.

Which of the following are true?
The MouseListener interface defines methods for handling mouse clicks.
The MouseMotionListener interface defines methods for handling mouse clicks.
The MouseClickListener interface defines methods for handling mouse clicks.
The ActionListener interface defines methods for handling the clicking of a button.
Ans : a and d.

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?
t.addTextListener(eh);
eh.addTextListener(t);
addTextListener(eh.t);
addTextListener(t,eh);
Ans : a.

What is the preferred way to handle an object’s events in Java 2?
Override the object’s handleEvent( ) method.
Add one or more event listeners to handle the events.
Have the object override its processEvent( ) methods.
Have the object override its dispatchEvent( ) methods.
Ans : b.

Which of the following are true?
A component may handle its own events by adding itself as an event listener.
A component may handle its own events by overriding its event-dispatching method.
A component may not handle oits own events.
A component may handle its own events only if it implements the handleEvent( ) method.
Ans : a and b.

Post a Comment

أحدث أقدم