Results 1 to 5 of 5
  1. #1
    trishtren is offline Member
    Join Date
    Feb 2011
    Posts
    53
    Rep Power
    0

    Wink using the mousedrag in a conditional loop

    Hey, iv been struggling trying to find a way to use the MOUSE_DRAGGED event in an if condition. I dont want to access it in the function that has to be declared below :

    Java Code:
    public void mouseDragged(MouseEvent e) 
    	{		
    	}
    Id like to access the mouse dragged event from an if condition like below :
    Java Code:
    if (e.MOUSE_DRAGGED == 506)
    {
     //do something, im using 506 as its the only drag event value i have found
    }
    So if anyone could show me a better way of using the drag event in an if condition id be very grateful :)

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Can you clarify your question greatly? What overall problem are you trying to solve and why won't a mouse listener and its mouseDragged method help you?

  3. #3
    trishtren is offline Member
    Join Date
    Feb 2011
    Posts
    53
    Rep Power
    0

    Default

    Part of the problem is that the mouse listener doesent seem to recognise there has been a mouse dragged event when i drag the mouse using the method below :
    Java Code:
    public void mouseDragged(MouseEvent e) 
    	{
    		System.out.println("mouse dragged");
    	
    	}
    Iv added the listener, as shown below:
    Java Code:
    PaintCanvas()
    	{
            //constructor
    	addMouseListener(this);
            }
    and this method works for the mouseclicked function but not mouse dragged, if i drag the mouse nothing happens at all. So im trying to achieve the same result using an if condition. Any advice would be great.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    That's because you have to add it as a MouseMotionListener to capture mouseDragged, not a MouseListener. Have you gone through the tutorials and API? It's all explained there.

  5. #5
    trishtren is offline Member
    Join Date
    Feb 2011
    Posts
    53
    Rep Power
    0

    Default

    ah i never realized thanks for the tips ill read through them now.

Similar Threads

  1. conditional statement
    By blindfolded916 in forum New To Java
    Replies: 12
    Last Post: 07-11-2010, 10:09 AM
  2. Moving whole content of JScrollPane by mousedrag
    By Taiko in forum AWT / Swing
    Replies: 4
    Last Post: 01-16-2010, 09:44 PM
  3. JSP Help - Conditional Meta Tags
    By jakavan in forum New To Java
    Replies: 0
    Last Post: 12-08-2008, 07:34 PM
  4. how to do conditional looping?
    By chennee72 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 09-09-2008, 01:38 PM
  5. JFrame Conditional Close
    By hemanthjava in forum AWT / Swing
    Replies: 10
    Last Post: 06-29-2008, 08:49 AM

Posting Permissions

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