Event Handling Design

Although the new event model is much improved over the old model, you may find yourself pining for the simplicity of the old model where you essentially had only one choice for handling events, namely, extending a component and embedding event handling code in the extension.[19] The new model, coupled with inner classes, allows for much more flexibility than the old event model. For instance, when handling events with the delegation-based event model you can:

[19] Actually, you could manually delegate event handling to another object, but it's a lot of work and is quite error-prone.

  • Use the old event model

  • Use the inheritance-based mechanism provided with the new model

  • Have components listen to themselves

  • Encapsulate the event ...

Get Graphic Java™ 1.2, Volume I: AWT, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.