This seems to not be reliably working as I only ever got it to work once surprisingly but never again. Every other time it fails and only adds to the end of the path as can be seen in the gif below.
What could be happening is that, each time you try to put down a point, thePath2D just adds on a new path to the existing path. What you may have to do is get the program to create a new Path2D each time you click. Then again, this creates a bunch of Path2D nodes which aren't connected. So you may have to somehow put all of these new Path2Ds together.
Hope that helps.