Java Paint Program Question

In my java class we've been asked to create a painter program that allows the user to draw on the screen (as with a paintbrush). I had no trouble creating the program and having it perform up to standards with what was asked, but something that troubles me and that the teacher could not really answer for me was this: how do I manage to make the thing drawn be fluid lines instead of random dots?

The program performs great when drawing slowly, but when drawing fast, the image drawn becomes 'dotted' and has a lot of gaps. Any help scratching this itch would be greatly appreciated.

p.s. I've tried rendering off-screen first, same results. I believe the problem is the way the mouse event is handled, but I have no idea how else to handle it (app must draw when left mouse button is down and erase when right mouse button is down)

Your best bet is to construct a GeneralPath with the points from the mouse listener and use the Graphics2D.draw(Shape) method to render it. You can append to the GeneralPath as new points are added, so you don't have to even maintain a point collection at all.

Just in case anybody wishes to know, I ended up creating an array of GeneralPaths, an array of int for brushsizes, and an array of Color for brush color, plus an extra GeneralPath outside the array to be able to draw as the user inputs.

Following are my event handlers:

private void formMouseReleased(java.awt.event.MouseEvent evt)
{
/*
*This event handler is used to be able to tell when the user lets go of the mouse button,
*which is necessary so the image drawn has separate lines instead of one big mess of connected
*things. The color and size of each path are finalized in this event handler.
*/
if (pathCount < paths.length)
{
paths[pathCount] = path; //finalize the path
if(!delete)
pColor[pathCount] = getColor(); //Set the color if not deleting
else if (delete)
{
pColor[pathCount] = this.getBackground(); //Else set the color to the background
delete = false;
}
pSize[pathCount] = getBrushSize(); //Set the brush size for this path
pathCount++;
path = new GeneralPath(); //Reset the path
}
stillPressed = false; //Starts a new path next time user drags the mouse
}
private void formMouseDragged(java.awt.event.MouseEvent evt) {
if (!evt.isAltDown() && !evt.isControlDown() && !evt.isMetaDown() && !evt.isShiftDown())
{
if (!stillPressed) //Start a new path
{
path.moveTo(evt.getX(), evt.getY());
stillPressed = true;
repaint();
}
else if (stillPressed) //Continues the path if user has not let go of the mouse button
{
path.lineTo(evt.getX(), evt.getY());
repaint();
}
}
else if (evt.isMetaDown()) //Erase stuff on screen
{
if (!stillPressed) //Starts a new path, this path will have the color be the same as background (see event handler above)
{
path.moveTo(evt.getX(), evt.getY());
stillPressed = true;
delete = true;
repaint();
}
else if (stillPressed) //Continues same path
{
path.lineTo(evt.getX(), evt.getY());
repaint();
}
}
}