An interface definition in Java can be thought of more like a contract or promise than anything else. By claiming to implement an interface, a class is promising that it will have an implementation for the methods defined within. For example, a class implementing ActionListener promises to provide an implementation for a method actionPerformed, which returns nothing and which requires an ActionEvent object to be passed into the method.
Only when the method is called by some other class does the ActionEvent object need to exist and pass in. In the interface definition and in the class's implementation, it merely assumes that an ActionEvent will be passed in. That's all. It's the exact same as any other method taking in a parameter-- the caller must provide the data in question, and the method simply makes use of it.
As for why actionPerformed requires an ActionEvent, that can be answered on two different levels:
- Because the interface definition for
ActionListener mandates it by requiring that exact method signature. (This is the "why won't it compile if I don't" answer.)
- Because the Java API designers, who created the interface, decided that that's how the interface should work. (It makes sense, because
ActionListener is supposed to listen for "action events", so it's only natural that an object with the action event's information should be passed in. It is the responsibility of the implementing class to act on the information provided. This is the "why did they make it this particular way" answer.)
What's the point of all of this? The answer is polymorphism: In the case of ActionListener, it is possible to register a whole group of ActionListeners with different implementations with a Swing component, and all of them can be invoked the same way since they all are guaranteed to have a method void actionPerformed(ActionEvent e). This means that the Swing component can only worry about the interface (what the behavior is expected to be) of each listener, rather than the implementation (how that behavior actually works and/or how to invoke it).