my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes Printing GUI current Coordinates in the GUI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Printing GUI current Coordinates in the GUI" Watch "Printing GUI current Coordinates in the GUI" New topic
Author

Printing GUI current Coordinates in the GUI

mike ryan
Ranch Hand

Joined: Aug 08, 2010
Posts: 210

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

Joined: Jul 26, 2007
Posts: 10426
    
    8

Component#getLocationOnScreen()


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
mike ryan
Ranch Hand

Joined: Aug 08, 2010
Posts: 210

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

Joined: Jan 20, 2009
Posts: 172

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.


SCJD 6, OCPJP7, Baroque Potion, G+
mike ryan
Ranch Hand

Joined: Aug 08, 2010
Posts: 210

Hi David,

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


Mike
 
GeeCON Prague 2014
 
subject: Printing GUI current Coordinates in the GUI