This article seeks to demystify listener interfaces in Java. For example, if you have come to Java from Visual Basic, listeners can seem confusing. If you use a button in VB it comes ready-made with a click event. The programmer doesn’t have to worry about how or where mouse or keyboard events will be processed. Not so in Java. Objects are not already event-enabled.
In what follows we will assume some familiarity with one of the most commonly used listeners, “ActionListener”. We will then create our own listener interface. This is a lot easier than you might think. Any beginner to intermediate level Java programmer should benefit from this discussion. Java conventions for capitalisation of classes and interfaces will be used for all built-in and programmer created classes. When referring to generic classes, for example, “listeners”, lower case names will be used.