- Nested Classes and Event Handling

Lubomir Stanchev · 2013

The chapter teaches how to write Java code that responds to events. We will show how to write code that responds to keyboard strokes, mouse movement, window closing, and so on. Since Java is an object-oriented language, we cannot directly tell Java to execute a method when an event occurs. Instead, we need to create an object that supports the method that needs to be executed when the event occurs and pass this object as a parameter. In other words, event handling is supported in Java by creating new classes and objects that belong to them. However, creating too many new classes can be burdensome. To simplify the code, Java allows us to create a class within a class and even within a method. The chapter describes the different ways of creating such nested classes in the context of event handling.

Read the paper · More papers on PaperTik