GUIs & the event model
Vocabulary and mental model — no project yet
Presentations from class
What you must be able to explain
- What a GUI is, and why interactive pages need events
- Sequential programs run line by line; event-driven programs wait for the next event
- Fire → Listen → Handle: an event is raised, a listener detects it, a handler responds
- JavaScript is event-driven from the start — browsers fire DOM events constantly
- Three ways to attach a handler; addEventListener is the one to default to
- The event object carries type, target, and other details into your handler
- Every event has capturing (down) and bubbling (up) phases
const btn = document.getElementById('myBtn');
btn.addEventListener('click', function () {
alert('Button was clicked!');
});Lines worth memorising
Fire → Listen → Handle is the vocabulary for the rest of the term.
The next step depends on whichever event happens next — not the next line in a list.
addEventListener is preferred over inline onclick handlers.