This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Problem with unwanted doubling of Buttons on a Panel  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have a big problem with my project. I wrote a game where a user can connect stars so that they make a constellation. The issue is that I have a GUI function that adds several Buttons to a Panel called connectDotsPanel (connectDotsGUI), it also adds some mouse listeners to it. Then in the end of a game cycle (after several panels change) I clear that connectDotsPanel and I call connectDotsGUI again (because in the end of a cycle it is possible that the user succeeded and then I change constellations to new ones or I require the user to make more connections) . The thing is that it seems like if I repeat the same constellations (if I don't go to the next cycle but repeat the previous one OR when I go level up and repeat a constellation that already appeared in a cycle of some lower level - the buttons double and the mouseClicked listener shows as If there were 2 stars in a specific spot, not one. I have no idea why, because I clear that Panel always before calling connectDotsGUI. Please, help me because I feel like I spent around 10 hours on that with no clue of what could be wrong in my code. Here I add some relevant fragments of my code:
 
Rancher
Posts: 2990
20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have no idea why, because I clear that Panel always before calling connectDotsGUI.



I would guess one of two problems:

1. You don't clear the panel like you think you do
2. You invoke the logic that adds the buttons twice.

So you need to add debug code to see the logical order of all you methods and display the number of component on the panel as each of your methods is invoked.
 
Karolina Andruszkiewicz
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what I would think too but I already checked these two things and :

1. I clear the panel correctly, I left only the removeAll() method without calling ConnectDots GUI again and the panel was totally clear.
2. I checked how many stars (buttons) are placed on the Panel each time the GUI is called and it was always the correct number, never doubled.

Seems like somehow my code remembers these buttons, even though I create them from scratch when ConncectDots GUI is called. Something must be wrong with that ConnectDots GUI function....
Additional info : the number of buttons that are overlapping is equal to the number of iteration of the same cycle (so to the times when the GUI of same star constellation is called). Maybe these are not the buttons that are overlapping but the action listeners are multiplied? Omg I'm loosing my hope.
 
Master Rancher
Posts: 3036
106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Karolina,

welcome to the Ranch and enjoy the stay!

I agree with Rob, my suspicion would also be the way you clear your GUI panel. Did you use the method 'remove()' or 'removeAll()' to get rid of the existing buttons? Can you show us that part of the code (and maybe some more code)?
 
Sheriff
Posts: 23963
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it were me writing that code I wouldn't write any code which tries to clear the components from a panel. I would just create a new panel and discard the old one.
 
Hey! Wanna see my flashlight? It looks like this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!