+ 12

Event handler functions vs normal functions

I have noticed that with event handler functions we include a parameter which can be given a random name, usually e or ev is used and we use this var to get information about the object, the part i dont understand is were this object comes from how does ev have access to the events methods and info 😅 can anyone explain in simple please

8th Mar 2019, 7:49 PM
D_Stark
D_Stark - avatar
6 Answers
+ 8
Tashi N , RISHABH MISHRA , Vaibhav Singh Sikarwar Thanks it makes sense now 😉👍
8th Mar 2019, 11:47 PM
D_Stark
D_Stark - avatar
+ 7
EventHandler is a functional interface and you define the type of Event it handles.... EventHandler<T extends Event>. The event itself is a signal from the OS (by interrupt request - irq) and the observers of this get notfied: https://stackoverflow.com/questions/29880768/how-events-are-generated-in-java
8th Mar 2019, 8:06 PM
Tashi N
Tashi N - avatar
+ 6
The e is the object of a sub class of event class like ActionEvent class this class knows some certain info about the hardware change going on in the system As you call them through your Event handler parameter it gets activated and does its job
8th Mar 2019, 8:29 PM
Vaibhav Singh Sikarwar
Vaibhav Singh Sikarwar - avatar
+ 6
Event functions are the functions which you can rewrite the function for any object that you made. Event functions are actually called like normal functions in class. You can call event functions in your own class or it can be already called by the framework classes itself. If event functions have not rewritten for an object which calls the event function, then the event function will not be called. Summary: -Classes have event functions. -Event functions are called in somewhere in the classes. -Event functions should be rewritten for any object that will call the event function.
9th Mar 2019, 10:00 AM
Yusuf
Yusuf - avatar
+ 4
Well event handler are included with specific parameters which can be given different name by writing var , but as I think normal function can't beat event handler for example like in html table tag a evenhandler is onClick which response on clicking the table like: <table border onClick="this is a table"></table> on clicking the table it will show , this is a table also there are many evenhandler which are supported in html
8th Mar 2019, 8:04 PM
RISHABH MISHRA
RISHABH MISHRA - avatar
+ 2
Thank you
26th Nov 2020, 1:11 AM
Gibran Berdeja
Gibran Berdeja - avatar