Listeners

Attaching to non java components

Page 1 of 1

7 Replies - 633 Views - Last Post: 05 October 2008 - 08:18 PM Rate Topic: -----

#1 stauffski  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 210
  • Joined: 03-November 07

Listeners

Post icon  Posted 05 October 2008 - 01:51 PM

I am writing a program that monitors the movement of the mouse throughout the entire screen. Currently I am using code that I wrote that loops infinitely which chews the crap out of the processor. I decided to redo my program to make it more efficient, but I was wondering if it is possible to attach a mouse moved listener to the screen, rather than the java frame. Bellow is my current mouse tracking code, which is also currently under reconstruction.

public double mouseX;
public double mouseY;

//this code runs in a while(true) loop in another thread
//separate thread
mouseX = java.awt.MouseInfo.getPointerInfo().getLocation().getX();
mouseY = java.awt.MouseInfo.getPointerInfo().getLocation().getY();
//extra code runs here dealing with program specific operations
//end of separate thread

//the above thread triggers code segments in the main thread based on certain test statements



The first version of my code was a bit sloppy, but I do believe if I can get a listener attached to the screen, a lot of the CPU will be freed up.

Thanks,
Stauffski

Is This A Good Question/Topic? 0
  • +

Replies To: Listeners

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2656
  • View blog
  • Posts: 11,204
  • Joined: 20-September 08

Re: Listeners

Posted 05 October 2008 - 01:55 PM

Quote

I decided to redo my program to make it more efficient, but I was wondering if it is possible to attach a mouse moved listener to the screen, rather than the java frame


If you mean can you get mouse events outside your Java app, then no, or at least not without native+JNI code and a native mouse hook
Was This Post Helpful? 0
  • +
  • -

#3 stauffski  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 210
  • Joined: 03-November 07

Re: Listeners

Posted 05 October 2008 - 03:28 PM

Well, sadly I know nothing about JNI.
So any tips or points in the right direction would be great :D
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Listeners

Posted 05 October 2008 - 03:47 PM

Just one recommendation
do not try to implements Java listener to non-Java component JNI or not
It is a sloppy design to start with
would be platform dependant
and really baddly architectured
Was This Post Helpful? 0
  • +
  • -

#5 stauffski  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 210
  • Joined: 03-November 07

Re: Listeners

Posted 05 October 2008 - 04:41 PM

So, from what I'm getting out of this, it sounds like I should stick with my process hogging code?
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Listeners

Posted 05 October 2008 - 04:47 PM

View Poststauffski, on 5 Oct, 2008 - 04:41 PM, said:

So, from what I'm getting out of this, it sounds like I should stick with my process hogging code?

Nothing wrong using C++
Nothing wrong using Java
Something wrong about making a half/half design

btw nothing wrong about using VB neither

This post has been edited by pbl: 05 October 2008 - 04:48 PM

Was This Post Helpful? 0
  • +
  • -

#7 stauffski  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 210
  • Joined: 03-November 07

Re: Listeners

Posted 05 October 2008 - 05:29 PM

Well, if I can't use JNI, and I don't want to use my code, how would I go about it? Anything in the defaultToolKit?
Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Listeners

Posted 05 October 2008 - 08:18 PM

View Poststauffski, on 5 Oct, 2008 - 05:29 PM, said:

Well, if I can't use JNI, and I don't want to use my code, how would I go about it? Anything in the defaultToolKit?


Nothing wrong about using JNI but ActionListener are kind of Java "architecture specific" so keep their action to Java

So you can make a Java component... put a listener to it... have the listener to call a Java method... (we are all still in Java) and then have this listener to call JNI to inform somebody else
but don't try to have the action listener to be in something else than Java
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1