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.
posted 16 years ago
Thanks! Your explanation was excellent. But I would still appreciate some sample code if possible. Thanks in advance
Howard Kung<br />SCJP 1.2<br />SCWCD<br />IBM Certified Specialist: WebSphere 4.0