Marcus Douglas wrote:Hi, I was wondering if someone could help me figure out what's wrong with my code. The idea behind it is straightforward: user clicks on an empty JPanel window and generates a circle that moves and bounces off the walls. Each click generates a new circle, each in its own thread, with a different colour. My code seems fine to me... .
Actually the code does pretty close to what you describe there. But tthere seems to be more expectations than what you spell out and the code doesn't do any of them
For example you want to create a new circle each time you click on the panel and you do on line 30. But it seems like you expect there to be multiple circles though your specification doesn't say there should be and the code doesn't hold multiple circles. If you want multiple circles you will need a collection of them, a List would probably work well. As it is you create a new circle but only ever hold one.
You also say you want the circle to "run" in its own thread. I guess you mean it should move in its own thread. And your code does that too. But it only moves once and doesn't paint until after the move so you may not see the move happen. I presume you want it to move over and over again. To do that you will need a loop of some sort to make it repeat.