Solved

how to custom a cursor

Posted on 2002-05-15
4
176 Views
Last Modified: 2010-03-31
as the title.
0
Comment
Question by:Arzu
  • 2
4 Comments
 
LVL 7

Expert Comment

by:yoren
Comment Utility
The answer is yes.
0
 

Author Comment

by:Arzu
Comment Utility
the question is how?
thank you.
0
 
LVL 1

Accepted Solution

by:
raid999 earned 50 total points
Comment Utility
Creating the custom cursor is done through a method in java.awt.Toolkit API:

public Cursor createCustomCursor(Image cursor, Point hotSpot, String name) throws IndexOutOfBoundsException

Toolkit is an abstract class, so first get the native implementation:
        Toolkit tk = panel.getToolkit();
Then create the cursor:
    Cursor cursor = tk.createCustomCursor(img, hotSpot, name);
Now, we can set the cursor on the panel:
     panel.setCursor(cursor);

The Full source Code:

import java.awt.*;
import java.applet.*;

public class CursorApplet extends Applet {


    public void init() {

        //load the image with the Media Tracker
        MediaTracker tracker = new MediaTracker(this);
        Image cursor = getImage(getCodeBase(), "music_note.gif");
        tracker.addImage(cursor, 0);

        try {
            tracker.waitForID(0);
        } catch (InterruptedException ie) {
            ie.printStackTrace();
        }

        Cursor cr = null;
        //get the toolkit for this environment
        Toolkit tk = getToolkit();

        try

            //this is the x,y coordinates of the image which
            //will actually do the "clicking"
            Point hotSpot = new Point(1, 1);

            //create the custom cursor
            cr = tk.createCustomCursor(cursor, hotSpot, "music_note");
        } catch (IndexOutOfBoundsException e) {
            e.printStackTrace();
        }
        //set the cursor for this applet component
        setCursor(cr);
    }
}



0
 

Author Comment

by:Arzu
Comment Utility
thank you raid999.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now