How to Remove the Cursor on Java Applets

Removing the cursor in a Java application helps developers minimize the interaction between the application and the user during wait times. It also limits the user's clicking action on an area of the form or window when there is no function to handle a mouse click. Removing the mouse cursor in a Java application involves "masking" it with a blank image. The method to remove the cursor is accomplished with only a few lines of code.

Instructions

    • 1

      Import the cursor libraries. To change cursor settings in Java, the compiler needs the proper libraries imported. The following text needs to be at the top of the Java code file:
      import java.awt.Image;
      import java.awt.image.MemoryImageSource;

    • 2

      Define the image that "masks" the cursor. The following code creates an image that is set to cover the cursor later in the application:
      int[] myPixels = new int[16 * 16];
      Image thecursorimage= CreateImage(new MemoryImageSource(16, 16, pixels, 0, 16));

    • 3

      Overlay the cursor pointer and remove it from use. The following syntax manipulates the cursor so that it's removed and hidden from the user:
      Cursor hidden_cursor= CreateCustomCursor(image, new Point(0, 0), "invisiblecursor");

    • 4

      Set the cursor settings. The following syntax removes the cursor from use from the user:
      setCursor(hidden_cursor);

Related Searches:

References

Comments

You May Also Like

Related Ads

Featured