• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printing GUI current Coordinates in the GUI

 
mike ryan
Ranch Hand
Posts: 210
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am currently learning about GUI's and have created one that has four JButtons (right,left,up,down),the component moves 10 px in the directiion of the button that is clicked.
I would like to show the current coordinates in the GUI as it is moved with the buttons.

How would i go about that? Which component or method can i use for that?


Thanks
Mike
 
Maneesh Godbole
Saloon Keeper
Posts: 11064
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Component#getLocationOnScreen()
 
mike ryan
Ranch Hand
Posts: 210
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Maneesh,

Thanks for the quick reply! I should have mentioned ia am using getX(), and getY() to find the current position of the component, i need to know how i can have those coordinates show within the GUI itself.
 
David Byron
Rancher
Posts: 175
Clojure Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mike ryan wrote:i need to know how i can have those coordinates show within the GUI itself.

The phrase "show within the GUI" is ambiguous.

One way to get the values would be to call .setTitle() on the JFrame itself and put your values in the title bar. That way, you could consult them even while laying out widgets within the frame.

Another way would be to set your values at text in a JLabel on a JPanel in the JFrame.

A different way would be to log the info and keep your GUI clean.
 
mike ryan
Ranch Hand
Posts: 210
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,

Thanks for the tipps!! I will give it a try


Mike
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic