Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #275
| From | "James Appleby" <james.appleby@THRWHITE.remove-dii-this> |
|---|---|
| Subject | Re: Listening to Mouse le |
| Message-ID | <1164917034.541182.108840@j44g2000cwa.googlegroups.com> (permalink) |
| Newsgroups | comp.lang.java.gui |
| References | <1164883540.536184.161880@j72g2000cwa.googlegroups.com>< |
| Date | 2011-04-27 15:26 +0000 |
| Organization | TDS.net |
To: comp.lang.java.gui
Thank you for your response Andrew. When I was first thinking about
this problem, I knew that simply using co-ordinates would be
inappropriate because if the application was continually tracking
co-ordiates, it would be rather heavyweight for the problem. It wasn't
until I read you post that I sat back and realised I could check
co-ordinates once the mouseExited command fired, giving me a sensible
solution.
private class FrameFocusListener extends MouseAdapter {
private JFrame focus;
// Take a reference to the component to track
public FrameFocusListener(JFrame frame) {
this.focus = frame;
}
public void mouseExited(MouseEvent event) {
if(event.getComponent().equals(focus)) {
// Get new frame position, in case it's changed
Rectangle bounds = focus.getBounds();
// There is a fuzzy area at the edge of the frame, trim inwards
// to avoid this
double minX = bounds.getX()+5;
double minY = bounds.getY()+25; // Also remove the titlebar height
double maxX = bounds.getWidth()+bounds.getX()-5;
double maxY = bounds.getHeight()+bounds.getY()-5;
Point mousePos = event.getComponent().getLocation();
mousePos.translate(event.getX(), event.getY());
double mouseX = mousePos.getX();
double mouseY = mousePos.getY();
if(mouseX < minX || mouseX > maxX ||
mouseY < minY || mouseY > maxY) {
System.out.println("Frame exited");
}
}
}
}
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
Back to comp.lang.java.gui | Previous | Next — Previous in thread | Next in thread | Find similar
Listening to Mouse leavin "James Appleby" <james.appleby@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000
Re: Listening to Mouse le "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000
Re: Listening to Mouse le "Thomas Kellerer" <thomas.kellerer@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000
Re: Listening to Mouse le "James Appleby" <james.appleby@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000
Re: Listening to Mouse le "Oliver Wong" <oliver.wong@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000
Re: Listening to Mouse le "James Appleby" <james.appleby@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000
csiph-web