Go Back   Java Programming Forums > Learning Java > Java Code Snippets and Tutorials


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 29-04-2009, 05:41 PM
Freaky Chris's Avatar
Senile Half-Wit
 

Join Date: Mar 2009
Location: UK
Posts: 621
Thanks: 2
Thanked 64 Times in 60 Posts
Freaky Chris will become famous soon enoughFreaky Chris will become famous soon enoughFreaky Chris will become famous soon enough

I'm feeling Cheerful
Default How to get Mouse Position

A common problem is wanting to retrieve the position of the mouse even if it is not within a Component of your application. This can be done using the following code, as an example. It Displays the mouse position every 100 thread tics.

Java Code
import java.awt.MouseInfo;

public class Mouse {
	public static void main(String[] args) throws InterruptedException{
		while(true){
			Thread.sleep(100);
			System.out.println("("+MouseInfo.getPointerInfo().getLocation().x+", "+MouseInfo.getPointerInfo().getLocation().y+")");
		}
	}
}



Reply With Quote Share this thread on Facebook
The Following User Says Thank You to Freaky Chris For This Useful Post:
muralidhar (01-01-2010)
Sponsored Links
Java Training from DevelopIntelligence
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Similar Threads
Thread Thread Starter Forum Replies Last Post
System Wide Mouse/Keyboard Hook Freaky Chris Java Native Interface 17 17-06-2009 06:06 PM
How to Control your computers mouse using the Robot Class JavaPF Java Code Snippets and Tutorials 3 11-02-2009 08:17 PM


100 most searched terms
Search Cloud
2d arraylist java actionlistener actionlistener in java actionlistener java addactionlistener addactionlistener in java addactionlistener java applications of oops could not create java virtual machine xp double format java double to int double to int java double to integer in java double to integer java eclipse shortcut keys eclipse tutorial for beginners exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double java get mouse position java java 2d arraylist java actionlistener java addactionlistener java convert list to map java double format java double formatting java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programming forum java programming forums java programming help java sendkeys java two dimensional arraylist java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton actionlistener jtextarea font jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream programming mutators and generics two dimensional arraylist java writing ipod apps

All times are GMT. The time now is 07:58 AM.
Powered by vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.