MOuse
Author |
Message |
MyPistolsIn3D

|
Posted: Tue Apr 19, 2005 5:08 pm Post subject: MOuse |
|
|
Is there a simple way in Java to make it so when you click the mouse, it returns the x,y value of where it clicked? Like the mouse.where command in turing? .... but not in an applet. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
rizzix
|
Posted: Tue Apr 19, 2005 5:36 pm Post subject: (No subject) |
|
|
yes u can get the location of the mouse from the component which the mouse clicked.
make use of the java.awt.event.MouseEvent which is passed to the void mouseClicked(MouseEvent e) method of the MouseListener event handler.
basically all you have to do is call the int getX(), int getY() methods of the MouseEvent object. |
|
|
|
|
 |
MyPistolsIn3D

|
Posted: Tue Apr 19, 2005 5:46 pm Post subject: (No subject) |
|
|
Yea, ive kinda been fooling around with the getX and getY commands, but i cant get them to work. Could you show me some sample code of what it would look like? |
|
|
|
|
 |
Kid_Goron

|
Posted: Thu May 26, 2005 8:42 am Post subject: (No subject) |
|
|
Just use this:
public void mouseDown (Event e, int newx, int newy)
{
x = newx;
y = newy;
return true;
}
create coordinates for int x, and int y wherever you need it to use.
all that you need to import is java.awt*;, which should already be imported |
|
|
|
|
 |
|
|