Question

In GUI programming, what are the Event and Event Handler classes and what are they used...

In GUI programming, what are the Event and Event Handler classes and what are they used dor?
0 0
Add a comment Improve this question Transcribed image text
Answer #1

In any programming language application that uses GUI (graphical user interface) which is event driven means user can interact with that application by using inputs and actions.
There are following steps or components in even handling:

  • Event: Change in state of an object is called Event.
  • Event Source: Input given by the user in the application.
  • Binding event with action: Fires the an action which is binding with that event.
  • Action listener: A listener is an object which gets notified when an event occurs. The listener fetch the required results and sends back to the user GUI.

Event describes the change in the state of any object like :

  • Pressing a button.
  • Voice input.
  • Entering text in text box.
  • Checkbox
  • Mouse event like clicking and dragging. Many more.

In java there are many packages like java.util, java.awt and java.awt.event which supports event handling.

For declaration of event handler class, the customised class should either implements a listener interface or extends a class that implements a listener interface.

public class CustomizedClass implements ActionListner{
public void actionPerformed(ActionEvent e) {
...//code that reacts to the action...
}
someComponent.addActionListener(instanceOfMyClass); //for listener
}

List of some important Event classes and their respective listener:

  • ActionEvent (ActionListener)- When actions are generated from buttons, menu items, etc.
  • KeyEvent (KeyListener)- Events generated when input is received from the keyboard in the form of text or text area.
  • ItemEvent (ItemListener)- Events generated from List, Radio Button, etc.
  • MouseEvent (MouseMotionListener)– Event generated by the mouse as clicking or dragging.

Thank you.


Add a comment
Know the answer?
Add Answer to:
In GUI programming, what are the Event and Event Handler classes and what are they used...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT