Solved

Detecting edges of frame, bouncing balls

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
allswap challenge 6 98
firstswap challenge 20 77
jsp insert to database example 2 24
Java: The Public Class Main 4 16
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

773 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