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:
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.
posted 1 week ago
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.
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)?