0

需要从简单的 java 应用程序中读取鼠标按钮状态(“按下”或“释放”)。可能吗?

谢谢!

4

2 回答 2

1

您可以使用MouseListener接口,或者它是有用的抽象实现MouseAdapter

public class MyMouseListener extends MouseAdapter {
    private boolean pressed = false;

    public void mousePressed(MouseEvent e) {
        this.pressed = true;
    }

    public void mouseReleased(MouseEvent e) {
        this.pressed = false;
    }

    public boolean isPressed() {
        return pressed;
    }
}
于 2012-11-13T17:48:56.793 回答
0

MouseEvent是您正在寻找的类

于 2012-11-13T17:47:05.567 回答