Results 1 to 4 of 4

Thread: Using a cursor

  1. #1
    notnumber6 is offline Member
    Join Date
    Nov 2007
    Posts
    8
    Rep Power
    0

    Default Using a cursor

    Hey guys,

    I want to create a basic application that imports the cross hair cursor, the overall aim of the project is to get co-ordinates depending on where the cursor is...

    Any chance?

    Thanks,

    Joel

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    You can set the System crosshair cursor with methods in the Cursor and Component classes
    Java Code:
    Component c = your component
    c.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
    // to change back
    c.setCursor(Cursor.getDefaultCursor());
    Add a MouseMotionListener for mouseMoved events or a MouseListener for mousePressed events to your component and you can get the coordinates of the mouse position on the component from their MouseEvent e.getPoint.

  3. #3
    notnumber6 is offline Member
    Join Date
    Nov 2007
    Posts
    8
    Rep Power
    0

    Smile

    When you say
    Java Code:
    Component c = your component
    What librarys do i need to import....

    Also is C the variable name you are initialising??

    So i could change it to Component crosshairCursor = your component?

    Also whats your component mean....

    Sorry for being thick, but a good reply hard wired

  4. #4
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    It was pseudo code. If I have a gui with a component displayed and I want to set the cursor for the component, ie, when the mouse is over that particular component the cursor will be set according to what I specified for the component, and if the component is:
    Java Code:
    JPanel panel = new JPanel();
    // The "panel" is the reference to the Component that we use to set the cursor.
    // Since JPanel extends from Component we can use the (inherited) Component
    // method [i]setCursor[/i] on the "panel" reference.
    panel.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
    If you do not like the System cursor you can make an image of what you want and use it with the Toolkit.createCustomCursor method to make what you want.

Similar Threads

  1. How to Hide cursor
    By priya in forum Java Software
    Replies: 1
    Last Post: 12-09-2010, 09:39 PM
  2. GUI cursor change problem
    By ludragon in forum Advanced Java
    Replies: 2
    Last Post: 01-09-2008, 10:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •