The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
February 2002



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Why for each atom of air

Posted by Hiran on February 16, 2002 at 12:02 PM

Matt, I understand the need for a seperate thread for each atom of the ball and for each atom of the matter that composes the walls so that the exact hit location can be determined, and from there the new direction can be determined. But why do you need a thread for each atom of air? I don't see how that affects the movement of the ball in any way.

> Hiran, of course it must be multi-threaded if you want a realistic simulation: for starters, you need a thread for each simulated atom in the ball, as well as one for each atom of air and for each atom of the matter that composes the walls. This program could be pretty resource-intensive, however...

> > Firstly, why does it have to be mutli threaded? Secondly, I'm not too familiar with applets, but take a look at the Java documentation (found on Sun's Java website). In terms of the logic for the ball bouncing, you would probably have to have two variables (x and y) that keep track of the balls coordinates. Then, have your applet redraw the ball everytime it x and/or y are incremented or decremented. In terms of making the ball move, and having it bounce back if it hits the side of the applet, have some way of specifying which direction the ball is moving (and hence which co-ordinates increment or decrement). Have a loop that changes your co-ordinate values based on the direction (and redrawing the ball everytime), and checking after every move to see if the either of the ball's co-ordinates have touched the sides of the applet, and if so, change the direction of the ball according to some logic that determines the new direction based on the position of the ball (ie, angle, co-ordinates, etc.). Hope this helps. If you have any specific questions, post some code with the specific question, and someone will then be able to help you.
> > Hiran

> > > hello guys. it's my first time here. i just wanna ask if any of you guys has a solution for my problem. i need multi threading java program that will make a blue ball bounce inside the applet, then bounces back as it hits the side of the applet. the ball is initiated by a mouse click! thank you!!! =)


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us