Solved

how to custom a cursor

Posted on 2002-05-15
4
182 Views
Last Modified: 2010-03-31
as the title.
0
Comment
Question by:Arzu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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.

691 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