Skip to content

Screenmate “Neko” in Java

by werner on July 16th, 2010

Neko is Japanese for cat. According to Wikipedia it was originally written for the NEC PC-9801. I know it from the OS/2 program of the same name.

(Image from Wikipedia commons)

The little kitten Neko chases the mouse cursor around the desktop. Once she’s over it and the mouse doesn’t move she’ll prepare to take a nap. If the mouse goes outside the desktop she will reach the border and try to dig for it. She’ll eventually give up, and fall asleep.

Many free and open source ports of Neko exist. I have adapted the Java Applet “Java Neko” by Chris Parent for the Desktop.

The cat is displayed on a JWindow which I have made transparent using the following command:

AWTUtilities.setWindowOpaque(window, false);

Since Neko is supposed to chase the cursor, we need to poll the mouse location in regular intervals using a Swing Timer. I query the location using a call to the MouseInfo class:
PointerInfo pointerInfo = MouseInfo.getPointerInfo()
Point mouseLocation = pointerInfo.getLocation();

We don’t want Neko to go outside of the Desktop area. I determine the bounds and insets of the desktop using the following code snippet:
GraphicsConfiguration gc = getGraphicsConfiguration();
Rectangle screenBounds = gc.getBounds();
Insets screenInsets = getToolkit().getScreenInsets(gc);

The rest of the code is pretty much identical with Chris’ Java applet.

You can download the file Neko.jar along with the source code.

Double click the .jar file to start it. Click on Neko to end the program.

Feel free to copy the source code and images. You can change it if you like, for your own Neko Java program.

From → Java

Comments are closed.