Results 1 to 11 of 11
Like Tree1Likes
  • 1 Post By ozzyman

Thread: How to detect object by going near to it

  1. #1
    Sudharshan is offline Member
    Join Date
    Mar 2012
    Posts
    2
    Rep Power
    0

    Default How to detect object by going near to it

    I am new to java i have plot of line if i go near to the line it should be highlighted for example in the below link
    How This Bear Market Compares - Interactive Graphic - NYTimes.com

    In this link when you go closer to the line it will be highlighted how to implement it.

  2. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Re: How to detect object by going near to it

    If you want something like that (in the link you provided), especially for a website, it would probably be better and a lot easier to do it in SVG & HTML5.

    If you still want to do this in Java you will need to look at a few things,

    Mouse Motion Listener: (to detect onmouseover events)
    How to Write a Mouse-Motion Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)

    Drawing lines with Java 2D:
    Drawing Geometric Primitives (The Java™ Tutorials > 2D Graphics > Working with Geometry)
    DarrylBurke likes this.

  3. #3
    Sudharshan is offline Member
    Join Date
    Mar 2012
    Posts
    2
    Rep Power
    0

    Default Re: How to detect object by going near to it

    Quote Originally Posted by ozzyman View Post
    If you want something like that (in the link you provided), especially for a website, it would probably be better and a lot easier to do it in SVG & HTML5.

    If you still want to do this in Java you will need to look at a few things,

    Mouse Motion Listener: (to detect onmouseover events)
    How to Write a Mouse-Motion Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)

    Drawing lines with Java 2D:
    Drawing Geometric Primitives (The Java™ Tutorials > 2D Graphics > Working with Geometry)
    thanks for the info i will try with the method described above but i have implemented when my mouse go above the line it is detecting but i want to detect line when my mouse cursor is 5 or 10 pixel away from line
    Last edited by Sudharshan; 03-13-2012 at 08:34 PM.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default Re: How to detect object by going near to it

    i want to detect line when my mouse cursor is 5 or 10 pixel away from line
    If you know where the mouse is and where the line is, you should be able to compute the distance between them.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,251
    Rep Power
    19

    Default Re: How to detect object by going near to it

    Quote Originally Posted by Norm View Post
    If you know where the mouse is and where the line is, you should be able to compute the distance between them.
    Line2D has a couple of methods for that...

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default Re: How to detect object by going near to it

    How do you know of all these methods?

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,251
    Rep Power
    19

    Default Re: How to detect object by going near to it

    By hanging around forums for years ;)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default Re: How to detect object by going near to it

    And having a brain like flypaper.

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,251
    Rep Power
    19

    Default Re: How to detect object by going near to it

    Like used flypaper :)
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,251
    Rep Power
    19

    Default Re: How to detect object by going near to it

    More seriously, since I'm not a programmer, I'm free to learn and remember whichever aspects of Java take my interest. So while I've picked up quite a bit about Swing and Java2D, I know next to nothing about networking, and have to look at I/O API 20 times to write a few lines of code to read a text file.

    You guys have to handle whatever the job throws at you, and if that doesn't happen to appeal to you it won't stick so well. Even so, your knowledge is several orders of magnitude greater than mine.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default Re: How to detect object by going near to it

    My background was mainframe assembly language. Lots of bits and bytes and I/O
    No OOP. All procedural functions.
    Java is a hobby after I retired.

Similar Threads

  1. JMF: Trying to detect webcam..help!
    By boblettoj99 in forum AWT / Swing
    Replies: 0
    Last Post: 11-09-2011, 11:51 PM
  2. Detect system shutdown/log off
    By cmpie1 in forum New To Java
    Replies: 0
    Last Post: 11-29-2010, 05:07 AM
  3. How to detect deadlocks
    By pinheiroa in forum Threads and Synchronization
    Replies: 1
    Last Post: 09-03-2010, 01:36 PM
  4. Unable to detect OS name
    By neetu.jainvi@gmail.com in forum Advanced Java
    Replies: 1
    Last Post: 12-09-2009, 04:56 PM
  5. Detect the ENTER key being pressed
    By aaronfsimons in forum New To Java
    Replies: 12
    Last Post: 05-16-2009, 08:48 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
  •