Solved

Detecting edges of frame, bouncing balls

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

743 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

10 Experts available now in Live!

Get 1:1 Help Now