getPos with MouseListener

Hello. I磎 trying to get the x and y values of the mouse when it磗 pressed. But I dont know how to get the values where I whant them.

I have made put the variables like this(-1 for a start to not exist):

privateint posX;

privateint posY;

public View(){

posX = -1;

posY = -1;

}

Then I guess I have to make a MouseListener method like this:

publicclass Posimplements MouseListener{

publicvoid mousePressed(MouseEvent event){

//get the x and y in px

int posX = event.getX();

int posY = event.getY();

}

publicvoid mouseReleased(MouseEvent event){}

publicvoid mouseClicked(MouseEvent event){}

publicvoid mouseEntered(MouseEvent event){}

publicvoid mouseExited(MouseEvent event){}

}

But now I dont know how to get the "posX" and "posY" values to another method.

If it should be to just write "posX", tell me and I post the whole class instead.

[2033 byte] By [Hunter78a] at [2007-11-27 3:51:45]
# 1
Instead of using a separate class for the mouse listener, use an anonymous class. That way the listener can access the members of the class that creates it. Google for "java anonymous class" to see how to use them.
hunter9000a at 2007-7-12 8:55:45 > top of Java-index,Java Essentials,New To Java...
# 2
Have tried some hours now to get this with "anonymous class". Thats the same as "Anonymous Inner Classes" right? Becouse cant find anything other ^^.Will read more about it tomorow becouse cant get it to work now. Will be back if I dont fix it. Thanks again :)
Hunter78a at 2007-7-12 8:55:45 > top of Java-index,Java Essentials,New To Java...