2014-03-02 4 views
0

간단한 자바 GUI에서 실시간 카운팅을 표시하려고하는데 optionPane을 사용했지만 기본 제공 버튼이 있습니다. 따라서 다음 번 번호를 표시 할 때마다 사용자는 버튼을 눌러야합니다. 간단한 GUI에서 숫자가 그 자체로 실행되도록하는 방법이 있습니까?GUI의 라이브 카운팅

예 :

for(int i = 0; i < 100; i++) 
{ 
    JOptionPane.showMessageDialog(null, i); 
} 
+0

[Swing Timers] (http://docs.oracle.com/javase/tutorial/uiswing/misc/timer.html) 및 [SwingWorker] (http://docs.oracle.com/javase)를 살펴보십시오. /tutorial/uiswing/concurrency/worker.html). – mre

+0

[this] (http://stackoverflow.com/a/21619240/2587435)를 참조하십시오. –

답변

0

그것의 사용자가, 당신은 javax.swing.Timer이 가장 좋은 건입니다 사용 100 대화 상자,

1

을 확인 팝업 클릭 수 1이 아닌 대화 마녀. 아래 예를 실행할 수 있습니다. 당신은 더에서 How to use Swing Timers

import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 
import javax.swing.JLabel; 
import javax.swing.JOptionPane; 
import javax.swing.SwingUtilities; 
import javax.swing.Timer; 

public class TimerDemo { 

    static int count = 0; 

    public static void main(String[] args) { 

     SwingUtilities.invokeLater(new Runnable() { 
      public void run() { 
       final JLabel time = new JLabel(String.valueOf(count)); 

       Timer timer = new Timer(1000, new ActionListener() { 
        public void actionPerformed(ActionEvent e) { 
         if (count >= 100) { 
          ((Timer) e.getSource()).stop(); 
         } else { 
          count++; 
          time.setText(String.valueOf(count)); 
         } 
        } 
       }); 
       timer.start(); 
       JOptionPane.showMessageDialog(null, time); 
      } 
     }); 
    } 
} 

  • 당신은 시계의 예를 here
  • 당신은 더 타이머 예 herehereherehere을 SSEE 수를 볼 수 있습니다 배울 수 있습니다.