Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 MOuse
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
MyPistolsIn3D




PostPosted: 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
Sponsor
sponsor
rizzix




PostPosted: 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




PostPosted: 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




PostPosted: 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
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: