繁体   English   中英

swing.Timer不停止

[英]swing.Timer does not stop

我在所有班级中都使用swing.Timer,但在所有计时器中都遇到了相同的问题,问题是:我的所有计时器第一次都运行良好,但是第二次所有计时器都没有停止

这是我所有计时器的代码

   Timer timer1;
   S= 0 ;
   ActionListener taskPerformer2 ; = new ActionListener() { 
    public void actionPerformed(ActionEvent evt) {                  
        if (  S == 10 ){            
           // My work   
           timer1.stop(); 
        }       
        S++;
        System.out.println(S + "A");
    }; 
 };
 timer1 = new Timer(20, taskPerformer2);
 timer1.start();

直接从事件中检索当前计时器。

public void actionPerformed(ActionEvent evt) {                  
  if (  S == 10 ){            
       // My work   
       ((Timer)evt.getSource()).stop(); // <-- this was changed
    }       
    S++;
    System.out.println(S + "A");
  }; 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM