jen
February 25th, 2000, 08:43 AM
Hi
How do I know when a listeners classes method is called if they have the same argument? If it is somehow automatically how will I know which one is called? Are all called the have the same method?
I would be very grateful for some help.
Jen
Jan Meeuwesen
February 25th, 2000, 08:57 AM
Hi Jen,
Let's take an example, the WindowListener. It's pretty simple. First of all it's not a class but an Interface.
Using the interface keyword, Java allows you to fully abstract the interface from its implementation. You can specify a set of methods which can be implemented by one or more classes.
When an event occurs, the event source invokes the appropiate method defined by the listener and provides an event object as its argument.
For example the WindowListener defines seven methods to recognize when a window is activated, closed, deactivated, deiconified, iconified, opened, or quit.
If you implement the WindowListener you should define the following methods:
void windowActivated(WindowEvent we)
void windowClosed(WindowEvent we)
void windowClosing(WindowEvent we)
void windowDeactivated(WindowEvent we)
void windowDeiconified(WindowEvent we)
void windowIconified(WindowEvent we)
void windowOpened(WindowEvent we)
In these methods you can define what should happen if this specific event occurs. For example :
void windowClosing(WindowEvent we) {
System.exit(0);
}
This exits the program if you click on the X (x-icon) on the top right of the window.
I hope this was usefull for your.
Greets,
Jan Meeuwesen
( If this answer is of any value to you, rate it! (bottom right in your browser under this text) )