我有一个跟随鼠标的JLabel代码。当用户退出窗口时,JLabel会说“退出”,并停留在用户所在的最后位置。问题是,“退出”仅在从顶部退出窗口时可见。这是因为JLabel在鼠标下。我想这样做,以便标签向下移动,这样我就能看到它,如果它退出并向上移动,如果它退出。我理解如何移动它,但我们可以根据条件移动它吗? 它在窗口显示得很好,我只需要根据退出位置将它放在鼠标的不同侧面。 这是我的代码:
var els = document.getElementsByClassName('change-color'),
target = document.getElementsByClassName('resources'),
changeColor = function(a) {
elements = document.getElementsByClassName("note");
for (var i = 0; i < elements.length; i++) {
console.log(elements[i])
elements[i].style.backgroundColor = "";
}
target = a.getAttribute('href');
element = document.querySelector('[data-id="' + target.substring(1, target.length) + '"]');
element.style.backgroundColor = a.getAttribute('data-color');
};
for (var i = els.length - 1; i >= 0; --i) {
els[i].onclick = function() {
hideOthers('footnotes-section', 'references-section', 'images-section', 'information-section');
showPanel('references-section');
changeColor(this);
}
}
非常感谢您花时间阅读本文,我非常感谢您为帮助其他程序员而付出的努力!
答案 0 :(得分:1)
public class GiraffeMouseHandler extends MouseAdapter implements MouseMotionListener
{
public void mouseEntered( MouseEvent event )
{
status.setText( "Entered" );
}
public void mouseExited( MouseEvent event )
{
status.setText( "Exited" );
}
public void mouseMoved( MouseEvent event )
{
//dimension is a reference of dimension of the main frame
if( ( dimension.getHeight() - event.getY() ) < 65 )
status.setBounds( event.getX(), (int)dimension.getHeight() - 65 , 50, 60 );
else if( ( dimension.getWidth() - event.getX() ) < 50 )
status.setBounds( (int)dimension.getWidth() - 50, event.getY(), 50, 60 );
else
status.setBounds( event.getX(), event.getY(), 50, 60 );
}
}