Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Eraser tool

843807Dec 27 2008 — edited Dec 29 2008
I am trying to make a paint program for a school final project and I currently have a good set of features such as pencil, rectangle, oval, line, etc. I want to implement a eraser tool but I don't know how to go about doing it. If I draw a filled white rectangle then it might overlap over the new things a person might draw after using the eraser tool. How should I go about doing this? Is there a good method for erasing stuff. Currently, I am using the vector class to store the coordinates of shapes, and redrawing them whenever there is a new addition. Here is a snippet of code:
if (tool == 0)
        {
            mouse_x = e.getX ();
            mouse_y = e.getY ();
            pencil_point.addElement (new DoodleColorPencil (mouse_x, mouse_y, mouse_prevx, mouse_prevy, current));
            repaint ();
            mouse_prevx = mouse_x;
            mouse_prevy = mouse_y;
        }
The DoodleColorPencil is a class that I have made that basically holds the coordinates of a line for the pencil tool. This is in the mouse dragged event. And in the paint method:
 DoodleColorPencil p;
        for (int i = 0 ; i < pencil_point.size () ; i++)
        {
            p = (DoodleColorPencil) pencil_point.elementAt (i);
            g.setColor (p.col);
            g.drawLine (p.x1, p.y1,p.x2, p.y2);
        }
Thanks for the help.

Edited by: ProgrammingNewb on Dec 27, 2008 8:34 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 26 2009
Added on Dec 27 2008
14 comments
628 views