You should get one mouse event for each click. What exactly is happening? Post the relevant code so we can have look - it may be something else (eg re-initialising the array each time the listener is called).
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
I don't understand why you are making a new MouseListener for each point. That's certainly not a normal way to proceed. I would just have one listener, initialised when the frame is ready to accept a polygon's worth of clicks. All it needs to do is add the points to an ArrayList of Points (ps why separate arrays for x and y???) until they have all been entered.
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
how do i make the program wait until it has the right amount of points? wouldn't it just get 1 and call the constructor normally, or not wait at all
This is a very important question! We all start out thinking in purely procedural terms - joined-up thinking - "I'll start a method that gets 5 points, processes them, and finishes" but GUI apps just don't hang together that way. You have to structure them as a series of steps/methods that get called by the events in the GUI. In this case something like:
Method 1: get number of points, start the mouse listener
Method 2: called by mouse events: add point. If all points are entered remove listener, call method 3.
Method 3: Process the complete set of points collected by Method 2.
It can take a bit of brain battering to get the hang of this kind of split-up logic, where the waits are implicit rather than explicit, but once you get the hang of it it becomes natural. Either way, you need to master it because that's how asynchronous programs (of which GUIs are a subset) are written.
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
I guess you didn't read my post. OK, that's your privilege. Anyway "what's the syntax" sounds like a request to write the code for you.
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
OK, I'm in a better mood now. Sorry if the previous post was a bit harsh. Anyway, as I said in before, structure it in 3 methods. You're not going to get any kind of sensible implementation in a single method, even if it has event handlers embedded.
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
Like I said earlier... "the waits are implicit rather than explicit". Please just try doing what I suggested - it really does work.
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
Method 1: get number of points, start the mouse listener
Method 2: called by mouse events: add point. If all points are entered remove listener, call method 3.
Method 3: Process the complete set of points collected by Method 2.
None of these methods has a wait.
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073