?
Solved

Detecting edges of frame, bouncing balls

Posted on 2011-02-14
5
Medium Priority
?
441 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 2000 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

AWS Certified Solutions Architect - Associate

This course has been developed to provide you with the requisite knowledge to not only pass the AWS CSA certification exam but also gain the hands-on experience required to become a qualified AWS Solutions architect working in a real-world environment.

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month8 days, 7 hours left to enroll

766 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