Using adapter classes is the easiest way to enable events. But you should know that there are other ways to set up events. In this lesson we will take a look at how to deal with implementing the event interfaces directly. We will only use the mouseListener and keyListener interfaces, but this will give you some idea why it is usually easier to just use the adapter classes.
First off, the one big advantage of adapter classes is that they take care of all the methods which must be implemented when implementing an interface. For instance, the mouseListener interface requires that you create methods called mouseClicked, mouseEntered, mouseReleased, mousePressed, and mouseExited. The keyListener interface requires that you create methods called keyPressed, keyReleased, and keyTyped.
Although we actually create all the methods required by the keyListener and
mouseListener interfaces, we only actually supply actions for two of them:
keyPressed and mouseClicked (as shown below).
Also notice the lines in the init method which actually load the event listeners.
NOADAPT.java
ASSIGNMENT: