Contents /
Previous /
Next
Define Custom Cursor (or make cursor disappear)
import java.awt.*;
import java.awt.image.MemoryImageSource;
public void hideCursor( Frame frame )
{
int w = 1;
int h = 1;
int pix[] = new int[w * h];
// Design custom cursor.
// int index = 0;
// for (int y = 0; y < h; y++) {
// int red = (y * 255) / (h - 1);
// for (int x = 0; x < w; x++) {
// int blue = (x * 255) / (w - 1);
// int green = 255;
// pix[index++] = (green << 24) | (red << 16) | blue;
// }
// }
Image image = Toolkit.getDefaultToolkit().createImage(
new MemoryImageSource(w, h, pix, 0, w));
Cursor cursor =
Toolkit.getDefaultToolkit().createCustomCursor
(image, new Point(0, 0), "custom");
frame.setCursor( cursor );
// Use some standard cursor.
frame.setCursor( new Cursor (Cursor.CROSSHAIR_CURSOR) );
//frame.setCursor( new Cursor (Cursor.WAIT_CURSOR) );
}