PDA

View Full Version : Bouncing Ball program




LOST1000
Nov 17, 2010, 10:07 PM
First and foremost, thanks in advance.

My program is suppose to have balls bouncing off the walls, changing colors each time they do so. I'm not sure what the issue is, however I am getting the following errors:



Ball.java:19: not a statement
addMouseListener{
^
Ball.java:19: ';' expected
addMouseListener{
^
Ball.java:76: invalid method declaration; return type required
public BallThread(int xCoord, int yCoord)
^



I can't figure out with the problem is, so any and all help is greatly appreciated.

Again, thanks in advance.


Code (http://pastebin.com/37zqC46g)



Catfish_Man
Nov 17, 2010, 11:35 PM
If addMouseListener is intended to be a function declaration it probably needs a return type and argument list...

Alternatively, you could be missing a semicolon somewhere before that, as it mentions.

chown33
Nov 18, 2010, 12:13 AM
Where are you learning this from: a book, an online tutorial, an example you're modifying, a class you're attending? The isn't something I'd expect anyone to write from nothing.

Whatever you're learning from, you've made a major mistake on line 20, with this code:
addMouseListener{

If you intended that to be a call to a method addMouseListener, then the {}'s need to be ()'s instead. If you intended something else, you'll have to explain what you intended. If you don't know what you intended, then at least tell us what you're learning from and be specific: book title and author; tutorial URL, example URL, class description.

When the code is that far wrong, it's not always possible to discern the intent just by reading the code. So I suggest that you describe what you intend the code starting at line 20 to be and do.

kainjow
Nov 18, 2010, 12:20 AM
You have 2 typos: "Hraphics" and "BallThred".

Also see How to Write a Mouse Listener (http://download.oracle.com/javase/tutorial/uiswing/events/mouselistener.html)

LOST1000
Nov 18, 2010, 12:27 AM
It's a class assignment sourced from a number of places, but mainly examples from class (beginners java).

You were right about the brackets - I see what I did there. Changing it cut out my two initial errors.

new code (http://pastebin.com/mKQcJ6nZ)

I am still getting this error, not exactly sure what it's asking me to do.

Ball.java:75: invalid method declaration; return type required
public BallThread(int xCoord, int yCoord)

Thanks again.

gnasher729
Nov 18, 2010, 04:17 AM
It's a class assignment sourced from a number of places, but mainly examples from class (beginners java).

You were right about the brackets - I see what I did there. Changing it cut out my two initial errors.

new code (http://pastebin.com/mKQcJ6nZ)

I am still getting this error, not exactly sure what it's asking me to do.

Ball.java:75: invalid method declaration; return type required
public BallThread(int xCoord, int yCoord)

Thanks again.

The error message says "return type required".

So what are the parts of a method declaration: There must be a name. There can be parameters, but they are not required. What else could there be that is actually required? Look at the error message. A big, big, big hint.

Ara-
Nov 18, 2010, 07:23 AM
The constructor must have the same name as the class