Bouncing Ball program

Discussion in 'Mac Programming' started by LOST1000, Nov 17, 2010.

  1. LOST1000 macrumors newbie

    Oct 24, 2010
    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: not a statement
    ^ ';' expected
    ^ 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.

  2. Catfish_Man macrumors 68030


    Sep 13, 2001
    Portland, OR
    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.
  3. chown33, Nov 17, 2010
    Last edited: Nov 17, 2010

    chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    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:
    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.
  4. kainjow Moderator emeritus


    Jun 15, 2000
  5. LOST1000 thread starter macrumors newbie

    Oct 24, 2010
    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

    I am still getting this error, not exactly sure what it's asking me to do. invalid method declaration; return type required
    public BallThread(int xCoord, int yCoord)

    Thanks again.
  6. gnasher729 macrumors P6


    Nov 25, 2005
    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.
  7. Ara- macrumors newbie

    Apr 24, 2010
    The constructor must have the same name as the class

Share This Page