[java] Getting mouse position

Started by
10 comments, last by Seyedof 22 years, 12 months ago
Hi Is there any way to get the mouse X and Y in a java applet? I dont wanna override the mouseMove event coz it SUCKS ! and i couldnt find any function which return the mouse coordinates, may you help me ? --MFC (The Matrix Foundation Crew)
--MFC (The Matrix Foundation Crew)
Advertisement
Don''t think you can get the mouse pos directly. If you want an alternative way of doing mouse events you can override processMouseEvent/processMouseMotionEvent on a component. It saves you a few bytes (useful for 4K comps), but either way you''ll have to store the mousePos yourself and update it whenever a mouse event occurs.
Why does overing the mouseMove method suck?

Seems fine to me!
hmmmm.....how exactly would you get the mouse position? I''m just starting Java and just need to know the specific methods to use. I have a bit of programming experience in C/C++(1.5 years) and java-script(5 years), so I don''t need to be coddled, just some method names and how they work.

AOL, so easy to use, no wonder it''s nothing but a bunch of retards

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

Well if you don''t like that method (works for me) here is another:

  int xcoord, ycoord;// in the init() method (for applets, constructor for apps)public void init() {    addMouseMotionListener(         new MouseMotionAdapter() {           public void mouseMoved(MouseEvent e) {               xcoord = e.getX();               ycoord = e.getY();               // other code               repaint();           }        }    );        // other crazy code }  


That''s it. So when the mouse moves, the coords will be set to the vars xcoord and ycoord.

Cheers, JP.

==============================================
I feel like a kid in some kind of store...
==============================================
www.thejpsystem.com
==============================================I feel like a kid in some kind of store... ============================================== www.thejpsystem.com

Hi
As more detail, i''m a C++ programmer and wanna do some java for
both fun and job, i''m porting all my c++ demo/game effects to
java applets, my first problem was to direct access to the pixel
buffer in a FAST way not just creating a memoryImageSource in each thread pass (which is both slow and easts memory) i asked that here, some replied me but none of them worked, at last found my answer in Hugi22 DiskMag (thanks to them).

In this case i wanna port my realtime bumpmapping effect, i need
to track the mouse movement to render new frames, but overriding
mouseMove event SUCKS coz it it slow and does not refresh fast
enough. I need some function like Win API''s GetCursorPos to get
the mouse position, as lilspikey said this is not possible,
well i will use the alternatives you guys offered, ive not yet tested them...



--MFC (The Matrix Foundation Crew)
--MFC (The Matrix Foundation Crew)
If you''re not getting mouse events often enough, it''d probably be worth setting your main thread to a lower priority. That way the GUI thread will get more processing time, which should have the effect of sending more moue events.
Hey Seyedof

I am interested in what data -> image solution you have found....

What method(s) are you using exactly?

is it setNewPixels?
just noticed that cfxweb have put some articles up about coding demo applets, it might be useful for you:

http://www.cfxweb.net/categories.php?op=newindex&catid=4
quote:Original post by loserkid

Well if you don''t like that method (works for me) here is another:

    int xcoord, ycoord;// in the init() method (for applets, constructor for apps)public void init() {    addMouseMotionListener(         new MouseMotionAdapter() {           public void mouseMoved(MouseEvent e) {               xcoord = e.getX();               ycoord = e.getY();               // other code               repaint();           }        }    );        // other crazy code }    


That''s it. So when the mouse moves, the coords will be set to the vars xcoord and ycoord.

Cheers, JP.

==============================================
I feel like a kid in some kind of store...
==============================================
www.thejpsystem.com

Okay, what file do I need to import to get this to work? I''m getting this error saying "new MouseMotionAdapter() cannot be resolved" and it points to the first m in the method name.

AOL, so easy to use, no wonder it''s nothing but a bunch of retards

Spyder''s Web Games

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

This topic is closed to new replies.

Advertisement