Well, I did go through the site mentioned in one of the earlier queries, but still i am not able to solve it........

I want an image to be displayed instead of the mouse cursor when it is over a panel.........which in the code is mainPane...........i think i am making a mistake in specifying the point.......plz help me out.......

the code i have written is as follows

public void mouseEntered(MouseEvent e) {}
	
//        	 Set cursor for the frame component
        	Toolkit toolkit = Toolkit.getDefaultToolkit();
        	Image image = toolkit.getImage("icons/handwriting.gif");
        	Cursor c = toolkit.createCustomCursor(image , new Point(mainPane.getX(),mainPane.getY()), "img");
        	mainPane.setCursor (c);
        }

If you're using Java 5 also known as 1.5...

From the Java 1.5 API Docs...

mouseEnter

@Deprecated
public boolean mouseEnter(Event evt,
int x,
int y)

Deprecated. As of JDK version 1.1, replaced by processMouseEvent(MouseEvent).

processMouseEvent

protected void processMouseEvent(MouseEvent e)

Processes mouse events occurring on this component by dispatching them to any registered MouseListener objects, refer to Component.processMouseEvent(MouseEvent) for a complete description of this method.

Overrides:
processMouseEvent in class Component

Parameters:
e - the mouse event
Since:
1.5
See Also:
Component.processMouseEvent(java.awt.event.MouseEvent)

But what it comes down to is you need to create a mouse listener and then add that mouse listener to your panel.

You could do the following code to get what you want:

public class YourPanel extends JPanel
{
  public YourPanel()
  {
     init();
  }

  private void init()
  {
    addMouseListener(new MouseCursorListener());
  }

  private class MouseCursorListener extends MouseAdapter
  {
    public void mouseEntered(MouseEvent e) 
    {
      //  Set cursor for the frame component
      Toolkit toolkit = Toolkit.getDefaultToolkit();
      Image image = toolkit.getImage("icons/handwriting.gif");
      Cursor c = toolkit.createCustomCursor(image , newPoint(mainPane.getX(),mainPane.getY()), "img");
      mainPane.setCursor (c);
  }
}

That might work for you.

Also, i Was just looking at your method you posted and it shouldn't have compiled even.

public void mouseEntered(MouseEvent e) {}  // <--  this } bracket needs to be removed.
	
//        	 Set cursor for the frame component
        	Toolkit toolkit = Toolkit.getDefaultToolkit();
        	Image image = toolkit.getImage("icons/handwriting.gif");
        	Cursor c = toolkit.createCustomCursor(image , new Point(mainPane.getX(),mainPane.getY()), "img");
        	mainPane.setCursor (c);
        }
public void mouseEntered(java.awt.event.MouseEvent e) {
                //Set cursor for the frame component
                linkLabel.setCursor (Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            }

This is the easiest way, if u want to use a predefined mouse cursor. This uses the static method getPredefinedCursor() in Cursor class.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.