Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: how can a rectangle of an Image intersect with a mouse cursor?

  1. #1
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default how can a rectangle of an Image intersect with a mouse cursor?

    im already a bit familiar of how does rectangle is used and important in manipulating images for an animation (COLLISIONS),

    but how can i make a statement that will detect that a rectangle of an object(image) has been intersected by a mouse cursor, i have no more questions about mouselisteners i just want to know how to get the BOUNDS of a mouse cursor, and is it possible?

     
      if (myImageRectangle.intersects my mouse rectangle) { // i dont know if this is fairly easy to do or possible in some way
     
                 < do something here>
      }


  2. #2
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: how can a rectangle of an Image intersect with a mouse cursor?

    finally got it (e.getComponent().getBounds()) , but i thought it will solve the issue of what i want,
    i think i need to rephrase what i need, sorry to make my statements a little bit confusing

    how can i detect IF I CLICKED or PRESSED an IMAGE(vice versa on RELEASE event) ? - i think im confident with my statement here as it is expressing my main concern
    Last edited by chronoz13; June 26th, 2011 at 06:46 AM.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: how can a rectangle of an Image intersect with a mouse cursor?

    how can i detect IF I CLICKED or PRESSED an IMAGE
    Get the cursor's/mouse's x,y position and see if it is in the rectangle where the image is.

  4. #4
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: how can a rectangle of an Image intersect with a mouse cursor?

    Get the cursor's/mouse's x,y position and see if it is in the rectangle where the image is.
    i tried with different getX(), point, of the mouse components , still im having some problems, but anyways, i just manually set a number where the mouse's X will intersects and do something

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: how can a rectangle of an Image intersect with a mouse cursor?

    im having some problems,
    Please explain. Add some printlns to your code to show the mouse's location and the rectangle's location.
    Then click on different parts of the rectangle and see what x,y is printed out for that location.

  6. #6
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: how can a rectangle of an Image intersect with a mouse cursor?

    oh sorry i didnt make it clear, i think the image's dimension's itself has some problems, that why my mouse's point(x and y) is not exactly intersecting with the image's rectangle bounds(x and y),

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: how can a rectangle of an Image intersect with a mouse cursor?

    It's hard to know if a point is in a rectangle if you don't know where the rectangle is.
    How do you show the image that you can't get its position?

  8. The Following User Says Thank You to Norm For This Useful Post:

    chronoz13 (June 26th, 2011)

  9. #8
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: how can a rectangle of an Image intersect with a mouse cursor?

    ill try to post the error in a shorter code if possible, well as of now i have a way to compensate with the problem, ill just post everything if theres any or another problem emerged, everything is getting in my mind all at the same time im getting sick , >.< well thanks for the help again norm

Similar Threads

  1. grow a rectangle in java
    By Khoatic in forum Java Theory & Questions
    Replies: 2
    Last Post: September 8th, 2010, 06:13 PM
  2. changing the splitpane's cursor
    By chronoz13 in forum AWT / Java Swing
    Replies: 2
    Last Post: February 8th, 2010, 12:11 PM
  3. Show Text With cursor
    By ravjot28 in forum AWT / Java Swing
    Replies: 1
    Last Post: January 20th, 2010, 10:02 AM
  4. Replies: 6
    Last Post: August 30th, 2009, 04:31 AM
  5. Dropping to graphic element dragged from JList
    By tua1 in forum AWT / Java Swing
    Replies: 1
    Last Post: November 29th, 2008, 08:22 AM