Hello,
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)
Here is the relevant part of my code:
Handling the mouse dragged event
private void formMouseDragged(java.awt.event.MouseEvent evt)
{
if (evt.isAltDown() == false && evt.isControlDown() == false && evt.isMetaDown() == false && evt.isShiftDown() == false)
{
if (pointCount < points.length)
{
point = new ColorPoint(getBrushSize(), getColor(), evt.getX(), evt.getY());
points[pointCount] = point;
pointCount++;
repaint();
}
}
else if (evt.isMetaDown())
{
if (pointCount < points.length)
{
point = new ColorPoint(getBrushSize(), this.getBackground(), evt.getX(), evt.getY());
points[pointCount] = point;
pointCount++;
repaint();
}
}
}
My paintComponent method
public void paintComponent (java.awt.Graphics g)
{
super.paintComponent(g);
for (int i = 0 ; i < pointCount ; i++)
{
g.setColor(points[i].getColor());
g.fillOval(points[i].x, points[i].y, points[i].getBrushS(), points[i].getBrushS());
}
}
Thanks!