This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
You don't need to use the Drag and Drop API unless you are going to be transferring the rectangle between components.
To get the rectangle to move within the same component that is drawing it, you would just add a MouseListener and a MouseMotionListener to that component. In the mousePressed() method, you would try to detect if the rectangle was clicked, if so, set a boolean. In the mouseReleased, if the boolean is set, unset it. In mouseDragged(), if the boolean is set, move the rectangle based on the location of the mouse, and repaint() the component. In the paint method you will paint the rectangle based off the class attributes that were affected in the mouseDragged method.
If this isn't clear enough, I can post some code if you want.
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Joined: Jul 22, 2002
Thanks! Your explanation was excellent. But I would still appreciate some sample code if possible. Thanks in advance