Event Handling
1. What Is an Event? (beginner)
Event = user did something (clicked, typed, closed!). Handling = code runs in reply (button → bill!). Flow: source (button!) → event object (ActionEvent!) → listener (your code!).
Button (source!) --click--> ActionEvent (what/where!) --dispatch--> actionPerformed() (your reply!)
Three steps: implement → register (addXListener) → handle (callback!).
4. Traps
- Forgot
addActionListener→ click does NOTHING (most common!). - Wrong method name (
actionperformd) → no override (use@Overrideto catch!). - Long work in handler freezes UI (use thread!).
5. Exam Points
- Counter program + 3 steps — 7 marks, very frequent.
- Delegation flow — 3-5 marks, frequent.