Getting Your Programs to Listen
A user event in Java is something that happens when a user performs an action with the mouse, keyboard, or another input device.
Before you can receive events, you must learn how to make an object listen. Responding to user events requires the use of one or more EventListener interfaces. Interfaces are a feature of object-oriented programming in Java that enable a class to inherit behavior it would not be able to employ otherwise. They’re like a contract agreement with other classes that guarantee the class will contain specific methods.
An EventListener interface contains methods that receive user input of a specific type.
Adding an EventListener interface requires two things. First, because the listening classes ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access