• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in dragging an object.

 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic