简体   繁体   中英

java mouse location

有没有办法只获得x坐标或y坐标形式

MouseInfo.getPointerInfo().getLocation()

??? This is pretty easy:

Point point = MouseInfo.getPointerInfo().getLocation();
double x = point.getX();
double y = point.getY();

Sure, try

MouseInfo.getPointerInfo().getLocation().x

or

MouseInfo.getPointerInfo().getLocation().y

发现它的乙醚

.getY() or .getX()
import java.awt.MouseInfo;
import java.awt.GridLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;

import javax.swing.*;

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM