aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Problem in dragging an object. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem in dragging an object." Watch "Problem in dragging an object." New topic
Author

Problem in dragging an object.

Neeba Rebbaca
Ranch Hand

Joined: Oct 21, 2008
Posts: 159
I have drawn a group of rectangles, i want to move and place it in a new place by draggging it. But it couldn't able to move it.




this is my code. Kindly help in solving the problem.>
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4638
    
    5

First off, I spot this in your code:
  • paintComponent(...) calls drawEquipment(...)
  • drawEquipment(...) calls repaint()


  • That's a strict no-no, as it's going to bog down the computer with painting events. Another no-no is inclusion of any business logic in painting methods, and I suspect you have that too. Then, I see two successive calls to repaint() at lines 81 and 82. Why?

    edit: You hve a call to g.create() at line 6 but you don't assign the value to a variable. The result is creation of a Graphics object that is never dispose()d, wasting resources.

    You also appear to be using parallel ArrayLists, and the code contains a lot of magic numbers. I strongly suggest you OOPify your code by creating a class that represents the parameters of an Equipment and knows how and where to paint itself.

    You can get some coding ideas regarding the above, including dragging of shapes, here.

    To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates your problem.

    luck, db
    There are no new questions, but there may be new answers.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Problem in dragging an object.