Results 1 to 2 of 2
- 04-08-2009, 06:07 PM #1
Member
- Join Date
- Oct 2008
- Posts
- 25
- Rep Power
- 0
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.
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?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())); } } }
- 04-08-2009, 08:25 PM #2
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
-
How to get Mouse and keboard events via HTTP for remote access
By shahzadcreative in forum NetworkingReplies: 1Last Post: 10-24-2008, 04:00 AM -
Menu item not working properly for mouse events
By Preethi in forum New To JavaReplies: 1Last Post: 09-23-2008, 08:56 AM -
Looping problem
By Tanilo in forum New To JavaReplies: 1Last Post: 08-01-2008, 06:34 AM -
Demonstration of mouse events
By Java Tip in forum SWTReplies: 0Last Post: 07-11-2008, 04:45 PM -
looping a function
By Username in forum New To JavaReplies: 2Last Post: 07-30-2007, 05:37 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks