Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Getting mouse position in 1.4.2 ?  (Read 2368 times)
0 Members and 1 Guest are viewing this topic.
Offline appel

JGO Wizard


Medals: 51
Projects: 4


I always win!


« Posted 2006-01-09 19:51:11 »

I'm using java 1.4.2 and I need to get the mouse position. I'm extending JFrame (MyGame extends JFrame) and while in 1.5 there is getMousePosition() there is nothing like that in 1.4.

Any ideas?

btw. this is for my 4k game, so if there is a simple way to do this then I appreciate that Smiley

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline Grand Poeba

Junior Duke





« Reply #1 - Posted 2006-01-09 20:00:55 »

I'm using java 1.4.2 and I need to get the mouse position. I'm extending JFrame (MyGame extends JFrame) and while in 1.5 there is getMousePosition() there is nothing like that in 1.4.

Any ideas?

btw. this is for my 4k game, so if there is a simple way to do this then I appreciate that Smiley

use mousemotionlistener? then when there is a mouseMoved event u gcan get the coordinates bij e.getX and e.getY
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #2 - Posted 2006-01-09 22:19:43 »

enableEvents(AWTEvent.MOUSE_EVENT_MASK|AWTEvent.MOUSE_MOTION_EVENT_MASK);

public final void processEvent(AWTEvent e){
   MouseEvent mouse = (MouseEvent)e;
   _mx=mouse.getX();
   _my=mouse.getY();
   me=mouse.getModifiersEx();
}

You can also use processEvent for keyboard stuff.

弾幕 ☆ @mahonnaiseblog
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline trembovetski

Senior Duke




If only I knew what I'm talking about!


« Reply #3 - Posted 2006-01-11 00:19:47 »

There's no way to get mouse position when the pointer is outside of java windows in 1.4.2.
If you need to track mouse over java windows only, then tracking the position with
MouseListener would work (check out java.awt.event.MouseMotionAdapter) as suggested by others.

2 oNyx: not the 1.1 stuff, pleeease!

Thanks,
  Dmitri
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #4 - Posted 2006-01-11 06:10:22 »

>2 oNyx: not the 1.1 stuff, pleeease!

If you can show me something smaller... Wink

(keep in mind that this is for 4k).

弾幕 ☆ @mahonnaiseblog
Offline appel

JGO Wizard


Medals: 51
Projects: 4


I always win!


« Reply #5 - Posted 2006-01-11 15:17:18 »

The way onyx pointed out to me works fine for me. thanks Smiley

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline trembovetski

Senior Duke




If only I knew what I'm talking about!


« Reply #6 - Posted 2006-01-11 23:46:22 »

>2 oNyx: not the 1.1 stuff, pleeease!

If you can show me something smaller... Wink

(keep in mind that this is for 4k).

I see then..
Offline arzi

Junior Newbie




Java games rock!


« Reply #7 - Posted 2006-01-18 14:34:44 »

Is there any way of resetting the mouse coordinates in Java? I would like the mouse cursor to be in the center of the screen (or window) in the start of the game. As far as I know, the mouse interrupt sends only coordinates relative to the last mouse position, which is also the way many other interfaces (DirectInput for example) handle the mouse input. So I'd like to know if there's a way to either reset the coordinates or get the original relative coordinates?
Offline Mr EEK

Senior Newbie





« Reply #8 - Posted 2006-01-18 15:20:13 »

Arzi,

You can set the mouse position (and do some other stuff) using java.awt.Robot.  (It's a class designed for automated GUI tests.)
Offline arzi

Junior Newbie




Java games rock!


« Reply #9 - Posted 2006-01-19 13:51:25 »

You can set the mouse position (and do some other stuff) using java.awt.Robot.  (It's a class designed for automated GUI tests.)

Thank you. I didn't I even know such a class existed Shocked Seems like my testing is going to a lot easier in the near future Smiley
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (37 views)
2014-10-17 03:59:02

Norakomi (28 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (28 views)
2014-10-15 16:18:58

TehJavaDev (52 views)
2014-10-14 00:39:48

TehJavaDev (54 views)
2014-10-14 00:35:47

TehJavaDev (42 views)
2014-10-14 00:32:37

BurntPizza (64 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (77 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!