Java 方法setRolloverEnabled启用了意外行为。

Java 方法setRolloverEnabled启用了意外行为。,java,swing,Java,Swing,我有这三张图片应该在点击时循环,当我点击时得到gif图片,其他两张图片没有响应,它们仍然在鼠标滚动时改变。 我已将setRolloverEnabled方法设置为false,以阻止在鼠标滚动时更改图像,但它们仍在继续更改。我看不出我的错误,有人能指出我的错误吗 public class ImageButton extends JFrame { private final JButton imgButton; private final Icon clickImage;

我有这三张图片应该在点击时循环,当我点击时得到gif图片,其他两张图片没有响应,它们仍然在鼠标滚动时改变。 我已将setRolloverEnabled方法设置为false,以阻止在鼠标滚动时更改图像,但它们仍在继续更改。我看不出我的错误,有人能指出我的错误吗

public class ImageButton extends JFrame {

    private final JButton imgButton;
    private final Icon clickImage;

    public ImageButton() {
        super("Lab button");

        Icon image1 = new ImageIcon(getClass().getResource("/imageBtn/Images/Image1.png"));
        Icon image2 = new ImageIcon(getClass().getResource("/imageBtn/Images/Image2.png"));
        clickImage = new ImageIcon(getClass().getResource("/imageBtn/Images/Image3.gif"));

        imgButton = new JButton(image1);
        imgButton.setRolloverIcon(image2);
        add(imgButton);
        ButtonClickEventHandler buttonEventHandler = new ButtonClickEventHandler();
        imgButton.addActionListener(buttonEventHandler);

    }   

    private class ButtonClickEventHandler implements ActionListener{

        @Override
        public void actionPerformed(ActionEvent arg0) {         

            imgButton.setRolloverEnabled(false);
            imgButton.setIcon(clickImage);
        }


    }
导入javax.swing.JFrame

public class ImageButtonApp {
    public static void main(String[] args) {
        ImageButton image = new ImageButton();
        image.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        image.setSize(660, 660);
        image.setVisible(true);
    }
}

对我来说似乎还可以(单击按钮后,鼠标在按钮上移动时,滚动图像不再显示)这很奇怪,你能单击3个图像吗?我只能单击一次,因为第二个图像不会在单击时显示,为什么会显示滚动功能呢。设置为false应该完全正确吗?当我单击它时,它会切换到第三个图像,并且不会改变-但我没有使用gif