如何在Java中获取鼠标按钮状态?

时间:2012-11-13 17:43:17

标签: java api mouse

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

谢谢!

2 个答案:

答案 0 :(得分: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;
    }
}

答案 1 :(得分:0)

MouseEvent是您正在寻找的课程