Solved

how to custom a cursor

Posted on 2002-05-15
4
181 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hibernate jars 4 60
mysql jsp example issue 32 75
Java program running SQL query 5 50
Java Eclipse Loop 3 31
In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

726 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