我在一个组件上有一个 MouseListener 并且想要监听 mouseReleased 事件,而不需要 mousePressed 事件。如何检测用户是否按下了另一个按钮、桌面或其他窗口(或任何东西,真的)并在我的组件上释放?
例如,在下面的例子中,我怎样才能让它打印“cool”,而不是“Not cool”?
titleBar.addMouseListener(new MouseListener()
{
@Override public void mouseReleased(MouseEvent e)
{
System.out.println("cool");//Detect this
}
@Override public void mousePressed(MouseEvent e)
{
System.out.print("Not ");//Without this having to happen first
}
@Override public void mouseExited(MouseEvent e)
{
}
@Override public void mouseEntered(MouseEvent e)
{
}
@Override public void mouseClicked(MouseEvent e)
{
}
});