簡體   English   中英

數字計時器幫助停止計時器和用戶輸入

[英]Digital Timer Help to stop timer and user input

我是JAVA的新手,當時有人要求我設計這種數字計時器。 我在停止計時器時遇到問題。 當用戶輸入分鍾和秒的值並按“暫停計時器”按鈕時,它將停止計時器並顯示數字,我的計時器如下所示:

 private void btStartTimerActionPerformed(java.awt.event.ActionEvent evt) {                                             
        javax.swing.Timer tm = new javax.swing.Timer(100, new ActionListener()
        {

            public void actionPerformed(ActionEvent evt) {
                btAddOneActionPerformed(evt);


            }
        });
tm.start(); 

用戶按下暫停按鈕時如何停止計時器?

![Timer GUI] [1]

所有幫助將不勝感激。

Swing Timer具有可以使用的startstop方法。

final Timer timer = ...;
timer.start();
...
JButton button = ... ;
button.addActionListener( new ActionListener(){
  @Override
  public void actionPerformed( ActionEvent e ){
    timer.stop();
  }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM