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 multi threaded?

Posted by Hiran on February 15, 2002 at 10:19 AM

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.

> 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