• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Problem in dragging an object.

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.>
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
     
    Uh oh, we're definitely being carded. Here, show him this tiny ad:
    Smokeless wood heat with a rocket mass heater
    https://woodheat.net
    reply
      Bookmark Topic Watch Topic
    • New Topic