HDTutorial
EN

Playback starts YouTube’s embedded player (privacy-enhanced mode).

How to use MouseListener, MouseAdapter and MouseEvent in Java Swing

95,726 views October 26, 2015 5:05

Watch on YouTube
ChannelTelusko

Description from the creator

All Java graphical components that send messages must:
Implement an EventHandler interface, i.e. ActionListener, and overwrite the method actionPerformed().

public interface MouseListener
extends EventListener
The listener interface for receiving "interesting" mouse events (press, release, click, enter, and exit) on a component. (To track mouse moves and mouse drags, use the MouseMotionListener.)

The class that is interested in processing a mouse event either implements this interface (and all the methods it contains) or extends the abstract MouseAdapter class (overriding only the methods of interest).

The listener object created from that class is then registered with a component using the component's addMouseListener method. A mouse event is generated when the mouse is pressed, released clicked (pressed and released).

A mouse event is also generated when the mouse cursor enters or leaves a component. When a mouse event occurs, the relevant method in the listener object is invoked, and the MouseEvent is passed to it.

Check out our website: telusko.com

Follow Telusko on Twitter: twitter.com/navinreddy20

Follow on Facebook:
Telusko : facebook.com/teluskolearnings
Navin Reddy : facebook.com/navintelusko

Follow Navin Reddy on Instagram: instagram.com/navinreddy20

Subscribe to our other channel:
Navin Reddy : youtube.com/channel/UCxmkk8bMSOF-UBF43z-pdGQ?su…
Telusko Hindi :
youtube.com/channel/UCitzw4ROeTVGRRLnCPws-cw?su…

About this tutorial

Telusko published this 5:05 video tutorial on October 26, 2015. It has been watched 95,726 times on YouTube.

Channel
Telusko
Duration
5:05
Published
October 26, 2015
Views
95,726
Likes
614

Tags

Share

Further reading

  • MouseAdapter (Java Platform SE 7 ) - Oracle docs.oracle.com

    Mouse events let you track when a mouse is pressed, released, clicked, moved, dragged, when it enters a component, when it exits and when a mouse wheel is moved. Extend this class to create a MouseEvent (including drag…

  • How to Write a Mouse Listener (The Java™ Tutorials > Creating a GUI ... docs.oracle.com

    Alternatively, use the corresponding AWT MouseAdapter class, which implements the MouseListener, MouseMotionListener, and MouseWheelListener interfaces. The following example shows a mouse listener. At the top of the wi…

  • Difference between MouseListener and MouseAdapter in Java - Stack Overflow stackoverflow.com

    MouseAdapter implements MouseListener already. The advantage to using MouseAdapter is so you don't have to define everything MouseListener forces you to. It's just an ease of use thing. If you don't need to define every…

  • MouseListener and MouseMotionListener in Java - GeeksforGeeks geeksforgeeks.org

    MouseListener and MouseMotionListener is an interface in java.awt.event package . Mouse events are of two types. MouseListener handles the events when the mouse is not in motion. While MouseMotionListener handles the ev…

  • SWING - MouseAdapter Class - Tutorialspoint tutorialspoint.com

    The class MouseAdapter is an abstract (adapter) class for receiving mouse events. All methods of this class are empty. This class is convenience class for creating listener objects. Class Declaration. Following is the d…

This tutorial in other languages