0

Hey

Im having a hard trouble drawing in a Java window so if there is a plugin that shows the coordinates in a Java window when I hover my mouse over that spot it would make my coordinate easier.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by adams161
0

you can implement a mouse motion listener:

http://download.oracle.com/javase/tutorial/uiswing/events/mousemotionlistener.html

and in on the mouse movement method track x,y to a variable to use in your paint components.

you can implement a mouse listener to detect clicks

http://download.oracle.com/javase/tutorial/uiswing/events/mouselistener.html

on a click write the current x,y as motion has updated it to writableX and writabley, then call repaint(), and then in your paint method use DrawString to write the cordinates of that click out somewhere in window.

if your drawing on a panel, make your panel class implement both listners. use the add method to add both listeners, and then you just need to copy in the methods of each listener ( with no code in at first). then add the code as i outlined, writing the x,y in motion and writing the writable x,y in click and repaint. You will get error methods if you use the implement and add but fail to copy in all methods. there is maybe 4 or 5 for each.

Mike

0

You can actually just use a motion listener and on each call to change in motion, mouse dragged in think, assign x,y and repaint and use drawstring in paint to print where the mouse is hovering at the moment, at a given spot like 50,50 on screen.

Mike

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.