You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用JLabel与ImageIcon实现简单动画时抛出异常的问题求助

使用JLabel与ImageIcon实现简单动画时抛出异常的问题求助

各位大佬好!我现在想在程序启动的时候做一个简单的静态动画效果,用了Timer和ImageIcon来实现,但运行起来好像出了问题,我实在搞不懂问题出在哪...

下面是我的实现代码:

int staticChecker = 0;
private void btnStartMouseClicked(java.awt.event.MouseEvent evt) {                                      
    pnlStart.setVisible(false);
    pnlMenu.setVisible(true);
    
    Timer t;
    t = new Timer(50, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            for (int i = 12; i <= 19; i++) {
                lblStatic.setIcon(new ImageIcon(getClass().getResource((12+staticChecker) + ".png")));
                staticChecker++;
                if (staticChecker >= 19) {
                    i = 12;
                    staticChecker = 0;
                }
            }
        }
    });

    t.start();
    
}                                     

我反复检查了好几遍还是没头绪,有没有大佬能帮我分析下问题出在哪呀?

备注:内容来源于stack exchange,提问作者William Hughes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.16 11:18:00