Solved

Detecting edges of frame, bouncing balls

Posted on 2011-02-14
5
426 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-
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now