tags:

views:

153

answers:

1

hey guys
i had made one module in my project,
on which user can draw any thing using pencil
now i want to create eraser for that drawing module
so i need that as soon as user click on that eraser button then, around my mouse cursor i want little rectangle shape around it.
so user can use it to erase the some parts in drawing.

may be smilier kind of things happen in mspaint but i am doing this in java - swing.

how to do this, any suggestion?

thanks in advance...
nitz.

+4  A: 

Instead of drawing a rectangle around the cursor, I would suggest to set a custom curser for the selected tool.

Just to show the API, (not tested) something like that sould work.

Image cursorImg = new ImageIcon("rectangle.gif").getImage();        
Point hotspot = new Point(0, 0);     // should be set to the center of your rectangle    
Cursor cursor = getToolkit().createCustomCursor(cursorImg, hotspot, "cursorname");

YourComponent.setCursor( cursor );

EDIT:

I have to add that getToolkit() is a method of java.awt.Component

stacker
@stacker, thanks for replay.....i will try this one, looking good.....
Nitz
@stacker, but there is one extra feature in my app. from where people can increase the size of eraser...so then what to?
Nitz
@Nitz in this case I would draw a rectangle in XOR mode
stacker
hummm..........
Nitz
@Nitz see i.g. http://stackoverflow.com/questions/880753/how-to-draw-rectangle-on-java-applet-using-mouse-drag-event or google "java draw rect xor example"
stacker