Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

MouseListener - mouseEntered question.  RSS feed

 
Andrew Gary
Greenhorn
Posts: 8
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know how to determine if the mouse enters something like a JButton or JTextField, but is there a way to determine if the mouse enters a certain portion of the JFrame?

Thanks
-Andrew
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a bit more CPU intensive, but a MouseMotionListener with mouseMoved can detect any movement of the mouse.
 
Kili Liam
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

You can create a Rectangle(...) and while the mouse is moving in the frame, you use the contains(..) method of the Rectangle class to determine if the mouse just entered "your" portion of the JFrame.

KL
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why create a Rectangle for that? That calculation is easy enough:
For the region with (x1, y1) as the top-left corner and (x2, y2) as the bottom-right corner, and (x, y) the current point.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!