I have to guess as you are only showing parts of the code.
Is your
mouse declared in the same class as your main
method at top level (member of a class)?
If that's the case you need to make
mouse a
static variable if you want to access it inside
main.
Generally,
you should not create your frame inside
main method.
See
this link.
Also, about:
I Johnson wrote:But placing "add(mouse)" or "addMouseMotionListener(mouse)" in that section doesn't work...
What do you mean by doesn't work? Does it compile? Does it throw an exception? Post the error message. Also, read
this page.
I Johnson wrote:...as it can't find "mouse", although the MouseMotionListener is declared before the main method.
It doesn't matter. If this is a class member, it could be declared after the
main method. The problem is, static methods (and
main is static) can only see static variables and your
mouse variable is probably non-static.