From the course: Learn Java with Swing

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

How to handle an event

How to handle an event - Java Tutorial

From the course: Learn Java with Swing

Start my 1-month free trial

How to handle an event

- [Instructor] When working with graphical user interfaces, we have components, now when a component is acted upon it generates an event. We also have a listener that listens for these events to happen and when a listener is invoked, it actually calls the event handler. When handling an event, it's important to know what component was acted upon, in other words what was the source of the event or what was the event that triggered this to happen. The component has a listener that waits for an event to happen, when it does it invokes the event handler. Examples include clicking a button, selecting an item in a list, typing into a text field. The handler needs to know what was the original source, was it a button, was it a list, was it a text field? After the handler has processed the event, it returns control to the originating source. The listener must be registered with the source component so it knows what to listen for. After an event is generated, an object is created. The object…

Contents