I am currently reading Head First
Java, and trying to supplement it with other sources. But things are starting to get hairy! As if constructors,
polymorphism, interfaces etc. alone weren't bad enough, event handling is blowing my mind away. Ok so below is what I think I know, and what confuses me. Your help in clarifying these concepts is very much appreciated.
What I know:
Interfaces define methods which must be later implemented by another class. They are useful because they allow objects to interact with the outside world, much like classes, but are more flexible from an inheritance standpoint.
Event handling - allows us to listen to user actions, i.e. mousePressed.
Event is a class,
Has sub-classes including MouseEvent class,
MouseEvent class has a MouseListener interface,
which defines methods like mousePressed.
By definition, mousePressed must be an abstract method, aka no body.
What I don't understand:
How does it know when the mouse has been pressed if there is no code in it?
Hope this makes sense!