Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By jim829

Thread: mouseAdapter

  1. #1
    riverhare is offline Member
    Join Date
    May 2013
    Posts
    4
    Rep Power
    0

    Default mouseAdapter

    Hi, guys! In my program i have to listen to the mouse, but something goes wrong. Here is my code:
    Java Code:
     MouseAdapter mouseHandler = new MouseAdapter() {
                    @Override
                    public void mouseMoved(MouseEvent e) {System.out.println("Mouse have been moved");}; 
    
    @Override
                    public void mouseClicked(MouseEvent e){                    
    
                 
                        System.out.println("CLICK");
                    }
                };
    The first method - mouseMoved - is working, but the second - mouseClicked - is not. Help me please, I really have no idea with what's wrong.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,030
    Rep Power
    6

    Default Re: mouseAdapter

    MouseAdapter is a combined class of three mouse related interfaces. So it implements empty methods of the MouseListener. MouseMotionListener, and MouseWheelListener interfaces. My guess would be that you did not register the handler in all the proper mouse listeners.

    Regards,
    Jim
    Last edited by jim829; 09-09-2013 at 10:48 PM.
    riverhare likes this.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    riverhare is offline Member
    Join Date
    May 2013
    Posts
    4
    Rep Power
    0

    Default Re: mouseAdapter

    Thank you, Jim! All I needed was to add one more string:
    addMouseListener(mouseHandler);
    Next time I'll be more accurate.

Similar Threads

  1. MouseAdapter Class?
    By backinqueez in forum New To Java
    Replies: 1
    Last Post: 11-18-2012, 02:37 PM
  2. Query on using MouseAdapter
    By halluc1nati0n in forum Java Applets
    Replies: 8
    Last Post: 07-02-2009, 09:04 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •