java在JButton上使用鼠标运动监听器?
嗨 我使用图像作为设置到面板的按钮 但现在我想在这张图片上使用鼠标运动侦听器动作 为此,我能做些什么
下面是图像的代码
JButton buttonForPicture = new JButton();
buttonForPicture.setBorder(new EmptyBorder(0, 0, 0, 0));
buttonForPicture.setOpaque(false);
buttonForPicture.setIcon(new ImageIcon("/Users/hussainalisyed/Documents/Images/pic9.jpg"));
panel5.add(buttonForPicture,BorderLayout.CENTER);
还有别的办法吗 或 ...
# 1 楼答案
阅读JButton API有一些方法可以改变鼠标滚动时的图标,如果你想这么做的话。在API中搜索包含“icon”的方法,查看您的选项
如果您只是想知道如何编写MouseMotionListener,那么请阅读How to Write a Mouse Motion Listener上Swing tutorail的部分,以获得一个工作示例
# 2 楼答案
我不确定你到底在问什么
您的按钮与其他任何JButton一样:
它捕捉整个按钮的运动事件,而不仅仅是图像