The program below outputs mouse coordinates anywhere on the screen every 500 msec and tries to get the cursor type.
The problem is cursor type always shows 0.
Sample output:
PHP Code:
C:\Program Files\Java\jdk1.6.0_23\bin>java cursorType
hello
(1058, 837)
Cursor Type is 0
(1058, 837)
Cursor Type is 0
(1103, 818)
Cursor Type is 0
(1104, 816)
Cursor Type is 0
(1107, 867)
*used php tags cause I like its color codingPHP Code:
import java.sql.Timestamp;
import java.util.Date;
import java.awt.Robot;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.SystemTray;
import java.util.Random;
import java.awt.Cursor;
class cursorType {
public static void main(String args[]) throws InterruptedException {
System.out.println("hello");
//1. Create the frame.
JFrame frame = new JFrame("FrameDemo");
//2. Optional: What happens when the frame closes?
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//3. Create components and put them in the frame.
//...create Label...
Label lbl = new Label("Welcome!", Label.CENTER);
frame.getContentPane().add(lbl, BorderLayout.CENTER);
//4. Size the frame.
frame.setSize(1919, 999);
//frame.getContentPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
//5. Show it.
frame.setVisible(true);
int cursorType;
while (true) {
Thread.sleep(500);
System.out.println("(" + MouseInfo.getPointerInfo().getLocation().x + ", " + MouseInfo.getPointerInfo().getLocation().y + ")");
cursorType = frame.getContentPane().getCursor().getType();
System.out.println("Cursor Type is " + cursorType);
}
}
}
I understand that .getCursor().getType(); has to work under the confines of a frame but is there a way to workaround this?
Bottom line is I want to capture the current cursor type anywhere on my screen.
Any ideas?