Solved

how to custom a cursor

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

Expert Comment

by:yoren
ID: 7010464
The answer is yes.
0
 

Author Comment

by:Arzu
ID: 7010467
the question is how?
thank you.
0
 
LVL 1

Accepted Solution

by:
raid999 earned 50 total points
ID: 7010493
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
ID: 7010584
thank you raid999.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

815 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

9 Experts available now in Live!

Get 1:1 Help Now