a timer in a for loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • javalearner123
    New Member
    • Nov 2008
    • 1

    a timer in a for loop

    hey

    i need help. ive been trying to put a timer in a for loop, but it doesnt seem to work. need help. thanx.

    i want the data printed in every array to be delayed by a few seconds

    heres the code
    Code:
    class ButtonListener implements ActionListener
    	  {
    	    private static final int TIMER_DELAY = 2000;
    	    protected static final int COUNT_MAX = 160;
    	    protected static final int DELTA = 1;
    	 
    	    public void actionPerformed(ActionEvent arg0)
    	    {
      
    	        	 InsertionSort(numbers);
    		 	      new javax.swing.Timer(TIMER_DELAY, new ActionListener()
    			      {
    			        public void actionPerformed(ActionEvent arg0)
    			        { 
    	        	 for(int i=0;i<5;i++)
    	        	 {
    
    	        	   for(int j=0;j<5;j++)
    	        	   {
    	        	     System.out.print(sortedArray[i][j]+ "\t");
    	        	   }
    	        	   //move to new line
    	        	   System.out.print("\n");
    
    	        	 }
    					   }
    				   }
    				   ).start();
    	    }
    	  }
    Last edited by Nepomuk; Nov 26 '08, 11:35 PM. Reason: Please use [CODE] tags!
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Have a look at the Thread.sleep() method; it makes the current thread sleep for a number of milliseconds.

    kind regards,

    Jos

    Comment

    Working...