Archived

This topic is now archived and is closed to further replies.

[java] Getting mouse position

This topic is 6077 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Why does overing the mouseMove method suck?

Seems fine to me!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hey Seyedof

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

What method(s) are you using exactly?

is it setNewPixels?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Hi
Anonymous Poster just get the Hugi Diskmag #22 from
http://www.hugi.de it has some articles about java demo
coding and i found a good solution for array-of-int->image
Thanks


--MFC (The Matrix Foundation Crew)

Share this post


Link to post
Share on other sites