Solved

Detecting edges of frame, bouncing balls

Posted on 2011-02-14
5
432 Views
Last Modified: 2012-05-11
Hi,

I'm working on  assignment, I'm trying to get a unfilled circle to bounce around the inside of a jframe, I'm using the usual rules that if the balls pos x/y are under 0 to reverse the direction and if they are over the frames width - Radius to do the same, but I'm still having the problem where the circle goes well beyond the bottom and and more than half the way off the right.

I've looked at many examples and they all seem to use the same method as I'm doing? I'm not using threads.

Can anyone offer any clue to what is wrong. Don't have code to hand at present; but is this a typical problem.

Darren
0
Comment
Question by:darren-w-
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 34888598
I guess, if you posted some code it will be possible to try to debug,
otherwise it is difficult to say why bottom is different than other boundaries.
Perhpas, someone who wrote something similar would know.

There are some pretty detailed instructions of such programs, which you probably know:
http://www3.ntu.edu.sg/home/ehchua/programming/java/J8a_GameIntro-BouncingBalls.html
0
 
LVL 10

Expert Comment

by:gordon_vt02
ID: 34897223
Make sure the content pane of the frame has the same dimensions as the frame itself.  Its possible, although not likely, that the content pane is larger.
0
 
LVL 13

Author Comment

by:darren-w-
ID: 34897361
Found the problem, a superclass had methods that defined the available height, and that sorted it, I've been reading the article further and it goes into how objects bounce against another ie not at perpendicular or horizontal angles.

I cant quite get to grips with how it works, assume its a bit of trigonometry, is there an easier way of getting the correct angle based on x,y values?
D
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34899141
Can you elaborate a little bit on your question about x and y  and angle?
0
 
LVL 13

Author Closing Comment

by:darren-w-
ID: 34970556
The link was very useful
0

Featured Post

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question