As I go through some old applications I wrote for various purposes, but never released, I thought I'd share the source code for a Java program that you can use to get the x/y coordinates or the mouse cursor (pointer) and RGB value of the pixel at that location. I've used this application for various reasons, including determining the location of something on screen, determining the width or height between two points, or getting the RGB value of a pixel on screen.
I'm sharing the source code for this "Java on Mac OS X" application, including the entire project -- which includes the Ant build script I use to build Java applications into native Mac OS X applications. This is all available in the "Download" section below.
Using the XYLocator is simple. Here's how to use it:
Here's what the application looks like when you first launch it:
And here's what it looks like after you've clicked a point on screen:
Probably the only confusing part about the app is that I need to take a picture of the Desktop, and then display it to you in an image. This is because the program is written in Java, and I don't know any other way to track the cursor location from Java. Once you understand that you're looking at an image, the app is easy to use.
P.S. -- I hope you like the Mac application icon, I made it myself. :)
If you just want to download the XYLocator as a Mac OS X application, you can use this link:
Once you've downloaded this zip file, just double-click it to open it, and then you can install this just like any other Mac OS X application.
If you'd rather download the XYLocator Java source code, you can download it from this link:
The current source code only works on Mac OS X systems, but if I get a bunch of requests to get this working on Windows or Linux, I'll be glad to put some time into it. Or, since you can get the source code here, you can get this working on Linux or Windows, and then send me the improved version. :)
P.S. - The source code is pretty crappy, but hey, I initially wrote this as an experiment nearly 10 years ago, and I was in a hurry, and atm, I don't feel like cleaning it up.
One other cool thing about having all the source code for this application is that it demonstrates how to create a native a Mac OS X application from a Java source code application. In fact, it demonstrates quite a few things about the "Java on Mac OS X" build and development process, and that may be as helpful as anything.
I hope my free XYLocator application helps you, either by letting you easily get the X and Y coordinates of stuff on your screen, or by helping you learn about Java, and creating a native Mac OS X application from Java source code.