Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Bouncing Ball program  RSS feed

 
Dave Rea
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, sorry if this is the wrong area for this question, but wasn't entirely sure where to put it and I am a beginner so here we are...

I'm simply trying to make a ball bounce, but using a println I can see that nothing in the area that calculates the path is running. But why is completely beyond me and all I get is a motionless ball.

I've only been learning Java for about 2 weeks, but now starting to think I'm not understanding anything.



I obviously have a Main class that then runs everything and creates a JFrame.

Thanks in advance for any help.
 
Campbell Ritchie
Sheriff
Posts: 53742
127
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The frame rate value is not a double, but an int cast to a double. Its value is not 0.025.

I haven't read the rest of the code.
I shall move you to our GUIs forum, where we usually discuss such questions.
 
Piet Souris
Rancher
Posts: 1783
55
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dave,

I must say: you kind of making it a bit complex to follow what's happening
in your Ball() constructor, but it should work.

First of all, Campbell's remark is spot on! It's one of those things that happens
to the most experienced again and again.

What is also stopping anything from runnig is: when the timer fires, it is calling the
actionPerformed() method. Now look at the body of this function. What is happening there?

And finally, although this is actually no error: your timer fires every 3 milliseconds. That
means the actionPerformed() will be called about 333 times every second. Are you sure
you want that speed? Your monitor will probably do a screen refresh of about
60 times a second. That's way slower than your timer speed!

Greetings,
Piet
 
Dave Rea
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to both of, I think with your advice the code is sorted. Now I just have to work on the math :S
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!