Event Listeners are the most important if you are working with Java Graphical User Interface. Event Listeners are all in the form of the interface and we have to implement these interfaces or the adapter classes of these interfaces if there are any. There are different types of events occurring on the graphical user interface, that's why we need different Event listener to listen to these events and then respond to the Events. In this article, we will have a brief introduction to each of the Event Listener that is out there in Java. So let's go into it.

List of Event Listeners in Java:-

  1. ActionListener
  2. ActionListener is probably one of the most widely used Event Listener in the Java Programs that we are writing in the day-to-day. When an action is performed by the user the "Action" is an event that fires. The most common example for the ActionListner will be when a user clicks on the Button the "Action" events fire. This is an Introduction to the Actionlistener and here are the Complete Details.

  3. AncestorListener
  4. When we remove a component or add a component to the component Hierarchy, Then this Event Listener handles the Event. We can specify the required response. This Interface is also handy when a JComponent becomes invisible or visible. Remember we have seen how we can make the visibility either true or false. This is an Introduction to the Actionlistener and here are the Complete Details.

  5. CaretListener
  6. Do you know about caret? When we are writing the cursor is indicating the point that we are currently inserting the text. We can detect the action of the Caret in two ways. First one, We can directly call the Methods of the JTextComponet, as they have methods for that. In the second method, we have to register the JTextComponet with the  CaretListner. This is an Introduction to the Actionlistener and here are the Complete Details.

  7. CellEditorListener
  8. This Event Listener is used very rarely, but the power can not be underestimated or ignored. CellEditor Listener is Used with the JTable and JAccessibleTable. This handler is called when there is some change in the CellEditor. This is an Introduction to the Actionlistener and here are the Complete Details.

  9. ChangeListener
  10. Woah, This is the most used Event Listener Interface in java. We have the brother of this EventListner which is very similar to this Event Listener Interface, The Property change Listener, The main difference between them is that the ChangeListner do not know about the Object that is changing, it does not know what is changed, but it knows that what object is changed. on the other side, the Property change listener carries both the information. So if you do not need to know about what is changed with the object then better go and use ChangeLisnter EventListner. A completed description of this interface can be found here.

  11. ComponentListener
  12. This is one of the event listeners Interfaces. This interface is used for receiving the events that occur on the Components. Anything that can have a display on the screen and to which the user can interact is considered to be an Object. Now, this is the interface is specially built for the events that occur on such components. A complete description of this interface is here.

  13. ContainerListener
  14. Remember we have studied about the container. The containers are components that host other components. When we add or remove a component to the container this Event Listener comes to play. The best example for this EventListener will be to add or remove a button from a JFrame. Details for this interface can be found here along with examples. 

  15. DocumentListener
  16. This EventListner is used by JTextField and JTextArea. I have already an example of this Event. You can check it right here. It is used to represent the Content of the JTextField or JText Field. You can also have a deep look at this Listener within this article. 

  17. ExceptionListener
  18. This Interface responds to the Events that are caused by internal exceptions. This interface has only one method which is exceptionThrown(Exception ex). we need to implement this method. and when there is some exception then it will be caught by this method.

  19. FocusListener
  20. This EventListener can handle the Focus Events that occur due to the gain or loses of the keyboard focus. The focus events can also be occurred due to the mouse. We can do some crazy things by capturing the focus events by registering the components to the FocusListener. Here is the detailed description of this interface if you want to have a look at that.

  21. HierarchyBoundsListener
  22. This interface is used when we are working with the hierarchy of the Components. This Event Listener can handle the events of resizing and moving of the ancestors. These events are provided for us, in order to get the facility of the notifications. If you are interested and want to know more you can click here to go and read the completed details with the example.

  23. HierarchyListener
  24. This interface is also useful to get hierarchy events. when the hierarchy received any change then this interfaces his methods capable of handling such events. The class which wants to listen to the hierarchy events should implement this interface. Remember is like the HierarchyBounds Listener, this interface is also used for notification purposes. Go to this article to know more about this event listener. 

  25. HyperlinkListener
  26. Sometimes we need to link one component to some outside objects. Like when we want to link a button to a URL, then we use the Hyperlink. In java we have HyperLinkListener, when there is any change occurring to the Hyperlink, this interface is Used. 

  27. InputMethodListener
  28. This interface receives all events related to the input method. When we have a component for the text editing, it has to implement an inputMethodListener to work with the input methods. An example will help you to understand more about InputMethodListener.

  29. InternalFrameListener
  30. When the window is first time created this interface handles all the events that are occurring there within the window. There are a number of events that can occur on the window for example the window can be created, can be disposed of, or can be iconified. We have an example with a complete explanation here. if you are interested to learn more about the InternalFrameListner. I recommend learning a little bit WindoListener before going to the Internal FrameListner. 

  31. ItemListener
  32. Even Listner is useful for components that his on/of State. For example, when we are working with the CheckBox, Check MenuItems, and toggle Buttons. We can do some crazy things with this interface and we will see them in the upcoming articles. 

  33. KeyListener
  34. The KeyListner Interface handles the Key Events. The Key Events occur when we are pressing and releasing the keys on the keyboard. we can handle these events. this is the most common one. we often want to know what key the user is typing and best in that event, we have to respond.

  35. ListDataListener
  36. We have two types of lists one is Mutable and the other is immutable. We can listen to the changes occurring or the events occurring on the Mutable list. In order to work with the ListDataListener, we have to use the ListdataModal. Do you want to know more about ListDataListener? 

  37. ListSelectionListener
  38. When there is a change in the list or a table, an event called the List Selection event is occur and we need to handle this Event. So this interface ListSelectioListener comes into play To listen and handle such kind of events. A detailed explanation along with a practical example can be found here. 

  39. MenuDragMouseListener
  40. Well, this is a high-level Event Listener. can be used in a very complex and high-level graphical user interface when we are working with Menus. This interface his several methods can be called with the different type of events that are associated with the Menu and mouse interaction. An example along with the explanation can be found in this article. 

  41. MenuKeyListener
  42. This interface is very much similar to the KeyLister but the only difference is that it is related to the events that are occurring on the events. if you know a little bit about the KeyListner then this interface is no longer difficult for you. Detailed explain on along with the example can be found here. 

  43. MenuListener
  44. All the events that can occur on the Event-related to the Menu. There are three possibilities that can occur in the menu. Menu cancel, Menu is deselected or the menu is selected. We can use the Menu Listener to handle all these events. You can learn more about the Menu Listener. 

  45. MouseListener, MouseMotionListener and MouseWheelListener 
  46. These two Interfaces are very related that's why I put both in one place.  We can track the mouse with the help of this interface we will look into the detail of all these three in different articles. three of them have similar functionalities somehow. 

  47. PopupMenuListener
  48. This Interface has some methods that make this interface very fantastic. This interface can handle events that can occur on a popup menu. we will look into this interface and all its method in this article (here).

  49. PropertyChangeListener
  50. Wolloah, This is the fun interface, some crazy people will be using it. When we are working with the graphical user interface, and for example, we have created a formated text Area, let say when someone writes there we are formatting the text in a specific way. The propertyChangeListener Interface will help us to listen to the change that his been occurred to the textField properties. Details can be found in this article. (here)

  51. TableColumnModelListener and TableModelListener
  52. TableColumunModelListerne comes into play when we are working with the table model. and the table model is used when we are creating the JTable we passed a table model to create a table. so all the events that are occurring to the Table Model that we have passed there to the JTable can be listened to by this Interface. The other one is way similar.

  53. TreeExpansionListener and TreeWillExapanListener
  54. In Graphical user Interface when we are working with the Tree component, These two interfaces are important at that time when we want to handle the collapse and expand events on the tree. These two or complicated and will be good if we can see an example of these two interfaces. 

  55. TreeModelListener
  56. We can trigger the data when it changes in the tree after displaying there in the tree graphical user interface. This Interface has 4 useful methods that we need to implement. When there is a change to the Nodes or there is another node inserted into the tree can be triggered by this interface. We will look into all of these methods. (here)

  57. TreeSelectionListener
  58. When the user selects a component either node or another tree this interface will handle these kinds of events. This interface will respond to these kinds of events. we will have a look on these events in this article.

  59. UndoableEditListener
  60. Interesting one, You might have seen the redo and undo functionalities in different software. This interface can give us the ability to undone changes. This is handy when we are working in text editors. We can undo certain operations. we will look into the example of this interface here.

  61. WindowFocusListener, WindowListener, and WindowStateListener
  62. All three are very much related, of course, there is a difference, in how they can handle the different event and listen to a different event. all of these three interfaces handle only one event which is called the WindowEvent. There are a lot of events in the window event, some of them are Opening the window, closing the window, focused window, and many more. An example will help us to know more about all of these three. 


we have mentioned almost all of the Java Event Listeners, Each of them by itself just needs to be explained and I hope you have a top-level idea on how and when each Event Listener can be Used. We will look into Some more details in the Upcoming Articles.
Let me paste an image of my IDE so you can see how I work. 

Event Listeners in java

Please do comment if you have any questions.

Post a Comment

Previous Post Next Post