1

我正在尝试实现 MouseOver 效果,就像它在 Java 中的 JavaScript 中用于 JButton 一样。我添加了一个 MouseMotionListener 并且它起作用了。如果我的鼠标触摸第一个按钮,我确实想设置 2 个其他按钮可见。所以这很完美..但如果鼠标不在按钮上,我不知道如何处理。我想在鼠标离开按钮后将按钮设置为 false

这是我的代码:

mouseover.addMouseMotionListener(new MouseMotionListener() {
    public void mouseDragged(MouseEvent arg0) {}
    public void mouseMoved(MouseEvent arg0) {

        del.setVisible(true);
        addone.setVisible(true);



    }

mouseover 是我想听的按钮。del 是另一个我想设置可见插件的按钮

对不起我的英语不太好:P

谢谢 !

4

3 回答 3

2

也许您想检查setRolloverIcon(),setRolloverSelectedIcon()方法,而不是使用MouseEvent.

于 2012-07-10T13:47:17.173 回答
2

您正在寻找一个 MouseListener,专门实现 mouseExited。

http://docs.oracle.com/javase/tutorial/uiswing/events/mouselistener.html

您可能希望使用 MouseAdapter 以避免被迫实现 MouseListener 的所有方法。MouseAdapter 只是一个实现鼠标监听接口的类。

http://docs.oracle.com/javase/6/docs/api/java/awt/event/MouseAdapter.html

于 2012-07-10T13:35:18.953 回答
1

Instead of using a MouseMotionListener. Use a MouseListener, this class has two methods called mouseEntered() and mouseExited() these should allow you to make the necessary changes as the mouse comes in and out of the button.

Here is a brief tutorial on MouseListeners

于 2012-07-10T13:34:19.623 回答