Match the following with respect to Event Driven Programming.

2021

Match the following with respect to Event Driven Programming.

image.png

Answer: D. i-b, ii-c, iii-aConcept Event-driven programming separates three distinct roles. An event is the occurrence itself — something the user or the system does, such as a mouse…

  1. A.

    i-a, ii-b, iii-c

  2. B.

    i-c, ii-a, iii-b

  3. C.

    i-b, ii-a, iii-c

  4. D.

    i-b, ii-c, iii-a

Attempted by 181 students.

Show answer & explanation

Correct answer: D

Concept

Event-driven programming separates three distinct roles. An event is the occurrence itself — something the user or the system does, such as a mouse click or a key press. An event listener is the registered piece of code that watches for occurrences of that kind and is notified when one happens. An event handler is the code that carries out the response once that notification arrives. Watching and responding are two different jobs held by two different pieces of code.

Application

  1. i. Event — produced when the user acts on a component, for example clicking a button or pressing a key. Nothing is being watched and nothing is being executed here; the item is the interaction itself. It therefore pairs with the table entry b, user interaction.

  2. ii. Event listener — in Java AWT/Swing a listener is an object implementing a listener interface such as ActionListener, registered on a component with a call like addActionListener(...). Its whole job is to watch for the occurrence, i.e. the event is monitored by this code. It therefore pairs with the table entry c, event monitored by code.

  3. iii. Event handler — the method body that runs once the listener has been notified, for example the body of actionPerformed(...). It carries out the response, i.e. it performs the said event. It therefore pairs with the table entry a, perform said event.

Cross-check

Term

What it does

Table entry

i. Event

the occurrence generated by the user or system

b — user interaction

ii. Event listener

registered code that watches for the occurrence

c — event monitored by code

iii. Event handler

code that runs in response to the occurrence

a — perform said event

Contrast this with the pairing i-b, ii-a, iii-c, which swaps the last two roles: it makes the listener execute the response and leaves the handler merely watching. The Java registration order disproves that reading — addActionListener(...) attaches the watcher first, and only when the event fires is actionPerformed(...) invoked to run the response. So the watching belongs to the listener and the execution belongs to the handler.

Result: the correct matching is i-b, ii-c, iii-a.

Explore the full course: Rssb Basic Computer Instructor

Loading lesson…