Core java tutorial for beginners
A tutorial blog which explains different core concepts related to Java along with programming examples

April 9, 2016 Categories: Event Handling. 1 Comment on Using Delegation Event Model

In this article we will learn about using delegation event model i.e., how to implement event handling in Java programs.


Following are the basic steps in using delegation event model or for handling events in a Java program:

  1. Implement the appropriate listener interface.
  2. Register the listener with the source.
  3. Provide appropriate event handler to handle the event raised on the source.


Key Events Handling


Following is a Java program which handles key events. In the program when the user types characters in the text field, they are displayed in a label below the text field.



Initial output of the above program is as follows:




After the user enters a character into the text field, the same character is displayed in the label beside the text field as shown in the below image:





Mouse Events Handling


Following is a Java program which handles both mouse events and mouse motion events. When the user performs a mouse event on the applet it is updated in the label.



Initial output of the above program is as shown below:




When the user moves the mouse cursor over the applet display area, then the output is as shown below:




When the user clicks on the applet display area, the output is as shown below:




Related Links:

Note: Do you have a question on this article or have a suggestion to make this article better? You can ask or suggest us by filling in the below form. After commenting, your comment will be held for moderation and will be published in 24-48 hrs.

1 Comment

You can follow any responses to this entry through the RSS 2.0 feed.

I’m really impressed together with your writing skills as neatly as with the layout in your weblog.
Is this a paid subject or did you customize it your self?

Either way stay up the excellent high quality writing, it is rare
to look a great weblog like this one these days..

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll Up