Bouncing Ball program

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

  1. macrumors newbie

    Joined:
    Oct 24, 2010
    #1
    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
     
  2. macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #2
    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

    macrumors 603

    Joined:
    Aug 9, 2009
    #3
    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:
    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.
     
  4. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
  5. thread starter macrumors newbie

    Joined:
    Oct 24, 2010
    #5
    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.

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

    Thanks again.
     
  6. macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #6
    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. macrumors newbie

    Joined:
    Apr 24, 2010
    #7
    The constructor must have the same name as the class
     

Share This Page