• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can't remove draggable object and renew a map

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear pros.

I have a Netbeans origin JFrame class OknoAdm with the main method and some other methods. It manages checkroom tags.

The tag class birka3D draws rectangle and manages its dragging and exiting jpanel:


In OknoAdm class - pressing a Button registers a tag to a name in Combobox:


In OknoAdm class - dragging a visual rectangle out of its Component should unregister the tag:





And here my coding has stuck. I tried it two ways:

1. Currently in b3d class I used a reference to OknoAdm object. This way I try to use in birka3D methods from OknoAdm - udalitBirki that remove tags and obnovitBirki that renews the display. But I doubt that I refer to that same object of OknoAdm that is run from main method, and not create a separate duplicate. Its the first time I try references - maybe I do smth wrong. Compiling this results no compile errors, but wrong behavior: adding new tag replaces existing tag and it is not removed while dragging it outside b3d panel.
2. Before that I tried to add MouseAdapter and MouseListener inside sozdatBirki method and run udalitBirki and obnovitBirki methods from inside of sozdatBirki method. But it resulted in error, because udalitBirki changed map contents while iterating it in sozdatBirki. Using ConcurrentHashmap removed the error but didn't provide the right behavior. Using 2nd way added tags and removed them while dragging outside the panel, but could remove more than needed when dragging or even adding.

Please advice.
 
Zon Horn
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Solved. Was wrong in referencing. Made object reference variable static in OknoAdm class and initialized this reference within main method. Then in birka3D class found this reference in OknoAdm class and used if (SwingUtilities.isLeftMouseButton(e)) {} in mouseExited to detect both dragging and exiting.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic