This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

addMouseMotionListener error

 
Derek Boring
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is probably a simple answer that will make me feel retarded, but i'm not seeing the problem. Please help guys!

I have a class I'm writing that extends JPanel. I want the JPanel to produce mouseMove events, but the code following this paragraph produces the error shown below it.



The error is:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Syntax error on token "actMove", VariableDeclaratorId expected after this token

It says the error is on the "actMove" that is in the "addMouseMotionListener" paranthesis.
Anybody know what I could be doing wrong?
[ July 24, 2007: Message edited by: Zero ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Zero",
Welcome to the JavaRanch.

We're a friendly group, but we do require members to have valid display names.

Display names must be two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profile and correct your display name since accounts with invalid display names get deleted.
 
Manuel Moons
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code you are showing us is correct! (supposing that you have an mMoved(MouseEvent me); method)

I am thinking that there is something else in the class file where you got the snippet from that is causing your problem. If you have not located your problem at this time it might be better that you show us an entire class that produces the error (compilation error).
 
Derek Boring
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First off, my apologies on the name thing.


I still haven't been able to find the problem. I'm posting the class below this. I don't know how much this explanation will help, but maybe the more info I give you guys, the more you can help: I'm making a platform game that uses a string array to store the level. Each cell of the level has an object, and a color, stored in the following format: "object-r.g.b" All the confusing code in the 'paint' event is decoding each cell and drawing it. The other methods are probably self explanatory, but let me know if clarification is needed. By the way, this code is not for the game itself, it's for a component of the level editor. This panel is to be shown inside a JScrollPane.

The bolded text is where the error occurs:


Anybody see anything I didn't?
[ July 25, 2007: Message edited by: Derek Boring ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't get the error message you do, but it doesn't compile because
addMouseMotionListener(actMove);
needs to be inside a method.

compiles OK when moving all the mouseMotionListener code to the constructor
 
Derek Boring
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that helped.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic