Swing has a Timer class

解决方案 »

  1.   

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;public class MyApp extends Frame implements ActionListener 
    {
       int t = 0;
       
    public MyApp()
    {
    this.addWindowListener (new WindowAdapter(){
    public void windowClosing(WindowEvent e){
    dispose();
    System.exit(0);
    }
    });
    }

    public static void main(String args[])
    {
       MyApp my = new MyApp();
       Timer timer = new Timer(1000,my);
       timer.start();;
    }

    public void actionPerformed(ActionEvent e){
       
       System.out.print(t);
       t = t+1;



    }

    }