2

I wanna create a pen tool using the Path2D Class. My problem is when comes the time to draw the shape we can see a dot at each intersection (see attached image).

https://i.stack.imgur.com/RSuID.png

Here is my code :

public void mouseDragged( MouseEvent e ) {
    path2D.reset();
    path2D.moveTo(last_x, last_y);
    path2D.lineTo( mouse_x, mouse_y );

    BasicStroke bs = new BasicStroke( 10, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND );

    // g is a Graphic2D object
    g.setStroke( bs );
    g.setColor( new Color( 0.0f, 0.0f, 0.0f, 0.3f) );
    g.draw( path2D );

    repaint()
}

I understand that it caused by the transparency and the fact that it is not one Path that is drawn. Tried with only one Path2D instance but at each repaint the path is draw over and over and the transparency disappear.

Any solution ??

Thanks in advance !

Niklas
  • 13,005
  • 23
  • 79
  • 119
Frank6
  • 1,193
  • 1
  • 11
  • 23
  • 1
    Are you drawing from mouseDragged()? Take a look here is a working example: http://stackoverflow.com/questions/7286808/issues-creating-a-pen-tool-with-javas-path2d – tenorsax Jan 16 '12 at 05:16

1 Answers1

0

The answer here was to use the triple buffer technic.

Frank6
  • 1,193
  • 1
  • 11
  • 23