Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

Check mouse clicked location

+15 votes
I know for the postal poke chase project that we used the panel.checkMouseClicked() method, but is there a single method to find out the x and y coordinates of where the mouse clicked on the drawing panel?
asked Oct 20, 2016 in CSC 211 (F16) by Alyssa Nestor (100 points)

2 Answers

+3 votes

Yes, after  panel.checkMouseClicked() returns true, then you can call panel.getMouseClickX() and panel.getMouseClickY() to get the coordinates.

answered Oct 22, 2016 by Forrest Stonedahl (100 points)
0 votes
If you want to know whether some location was clicked, maybe a graphic button, I would suggest making some kind of if statement for what will happen, and set the condition to check whether the coordinates of where the mouse clicked fall within in a certain range, determined by where is the place you want to check if clicked.
answered Oct 20, 2016 by Sara Estrada (100 points)