Results 1 to 2 of 2
  1. #1
    busdude is offline Member
    Join Date
    Oct 2008
    Posts
    25
    Rep Power
    0

    Default Need help with looping mouse Events.

    I'm trying to add several different points that the user clicks into an ArrayList, but I'm not sure how to get a new mouse event at a different location. It just adds the coordinate of the first point several times.


    Java Code:
    ArrayList points = new ArrayList<Point2D.Double>(); (declared outside of mousePressListener class)
    
    class MousePressListener implements MouseListener
          {
             public void mousePressed(MouseEvent event)
            {
    if (event.getButton() == event.BUTTON1)
    {
        for (int a = 0; a < 3; a++)
                    {                    
    points.add(new Point2D.Double(event.getX(),event.getY()));       
                    }
    
    }
    }
    Trying to get the user to click three points and insert them in an array list, but it seems it adds the same co-orinate(the first point) 3 times, how do I generate a new mouse event within this method?

  2. #2
    markw8500's Avatar
    markw8500 is offline Senior Member
    Join Date
    Jul 2008
    Location
    Pennsylvania, USA
    Posts
    136
    Rep Power
    0

    Default

    Without seeing all the code, I think you need to take out the loop... Because each time the mouse button is pressed your program will grab the current point. So in your program the user presses the mouse once and the loop adds the current point to the arraylist 3 times... Hence your dilemma...
    Who Cares... As Long As It Works...

Similar Threads

  1. Replies: 1
    Last Post: 10-24-2008, 04:00 AM
  2. Menu item not working properly for mouse events
    By Preethi in forum New To Java
    Replies: 1
    Last Post: 09-23-2008, 08:56 AM
  3. Looping problem
    By Tanilo in forum New To Java
    Replies: 1
    Last Post: 08-01-2008, 06:34 AM
  4. Demonstration of mouse events
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-11-2008, 04:45 PM
  5. looping a function
    By Username in forum New To Java
    Replies: 2
    Last Post: 07-30-2007, 05:37 PM

Posting Permissions

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