Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Multithreading Issues

 
Marcus Douglas
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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, but maybe I just am looking at it too hard. I don't think the overridden run() method is being called because the circle isn't moving. Also, it's not creating additional threads. Any help would be greatly appreciated. Multithreading is a new concept for me, so I still am trying to figure this out. The current code subclasses Thread class anonymously, but I've tried multiple configurations. I tried creating a separate class for creating the circles and implementing Runnable and I've tried using that class as a named subclass of Thread.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the ranch!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!