Advertisement
funaquarius24

DataTask

Sep 25th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. package mine.test;
  2.  
  3. public class DataTask implements Runnable{
  4.     private int sleepTime = 300; //In milliseconds
  5.     private int division;
  6.     private int end;
  7.     private int start;
  8.     private Test test;
  9.    
  10.     //Am drawing a parabola here... so I need the x-values.
  11.     public DataTask( int start, int end, int division, Test test ) {
  12.         this.start = start;
  13.         this.end = end;
  14.         this.division = division;
  15.         this.test = test;
  16.     }
  17.    
  18.  
  19.     @Override
  20.     public void run() {
  21.         try {
  22.             int count = ( end - start ) / division; //am interested only on the integer part
  23.            
  24.             for( int i = 0; i < count; i++ )
  25.             {
  26.                 int xValue = start + division * i;
  27.                 int yValue = ( int )Math.pow( xValue , 2 );
  28.                 test.dataset.add( xValue , start + 0.0, end + 0.0, yValue);
  29.                 Thread.sleep( sleepTime );
  30.             }
  31.            
  32.            
  33.         }catch( InterruptedException ex ) {
  34.             ex.printStackTrace();
  35.         }
  36.        
  37.     }
  38.    
  39.     public void setSleepTime( int sleepTime )
  40.     {
  41.         this.sleepTime = sleepTime;
  42.     }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement