Icon icon = new ImageIcon(getClass().getResource( "/img/icon.gif" ) );
aButton = new JButton("Its a button", icon);
是否有某种方法可以阻止动画播放?我正在考虑分配 gif 的静态 jpg,然后当我悬停时,分配动画 gif,但我认为没有移除鼠标的事件,MouseMotionListener
因此我可以加载静态 jpg。
gif 在按钮中循环,但是,如果我将鼠标悬停在它上面,它就会消失。
如果我的鼠标光标不在按钮上,如何使 gif 静态?
如果我使用MouseMotionListener
,如果我取下鼠标,它会触发事件吗?
@Override
public void mouseMoved(MouseEvent e) {
//play the gif
//if I take mouse off, call some method to stop playing animated gif
}
@Override
public void mouseDragged(MouseEvent e) {
}