Results 1 to 3 of 3

Thread: ClickCount

  1. #1
    AndrewM16921 is offline Senior Member
    Join Date
    Jan 2009
    Location
    CA, USA
    Posts
    264
    Rep Power
    6

    Default ClickCount

    I'm working with a MouseListener.mouseClicked method, and I have two different actions that I want to occur for a single-click and a double-click. But, it seems the the double-click fires two events, one with clickCount=1, and one with clickCount=2? So, how do I determine if a MouseEvent with clickCount=1 is part of a double click event?

    Simple example:
    Java Code:
    import java.awt.Dimension;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import javax.swing.JFrame;
    
    public class ClickFrame extends JFrame
    {
    	public ClickFrame()
    	{
    		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    		this.setSize(new Dimension(200, 200));
    		this.addMouseListener(new MouseListener()
    		{
    			@Override
    			public void mouseClicked(MouseEvent e)
    			{
    				System.out.println(e.getClickCount());
    			}
    			
    			@Override
    			public void mouseEntered(MouseEvent e)
    			{
    			}
    			
    			@Override
    			public void mouseExited(MouseEvent e)
    			{
    			}
    			
    			@Override
    			public void mousePressed(MouseEvent e)
    			{
    			}
    			
    			@Override
    			public void mouseReleased(MouseEvent e)
    			{
    			}
    		});
    		this.setVisible(true);
    	}
    	
    	public static void main(String[] args)
    	{
    		new ClickFrame();
    	}
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default Re: ClickCount

    Start a timer after the first click, and if a second click does not occur in that time, do the single-click event?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    AndrewM16921 is offline Senior Member
    Join Date
    Jan 2009
    Location
    CA, USA
    Posts
    264
    Rep Power
    6

Posting Permissions

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