1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| package DrawReadandLearn;
import java.awt.Color;
import java.awt.Graphics2D;
import java.util.Random;
public class Tasks implements Runnable{
private int sleepTime; // random sleep time for thread
private String threadName; // name of thread
private static Random generator = new Random();
public void DrlDrawRect(Graphics2D g2, String name, int x, int y, int dx, int dy, Color color){
threadName = name;
sleepTime = generator.nextInt( 5000 );
public void run()
{
try // put thread to sleep for sleepTime amount of time
{
System.out.printf( "%s going to sleep for %d milliseconds.\n",
threadName, sleepTime );
Thread.sleep( sleepTime ); // put thread to sleep
}
catch ( InterruptedException exception )
{
exception.printStackTrace();
}
System.out.printf( "%s done sleeping\n", threadName );
}
}
public void DrlDrawCircle(Graphics2D g2, String name, int x, int y, int dx, int dy, Color color){
threadName = name;
sleepTime = generator.nextInt( 5000 );
public void run()
{
try // put thread to sleep for sleepTime amount of time
{
System.out.printf( "%s going to sleep for %d milliseconds.\n",
threadName, sleepTime );
Thread.sleep( sleepTime ); // put thread to sleep
}
catch ( InterruptedException exception )
{
exception.printStackTrace();
}
System.out.printf( "%s done sleeping\n", threadName );
}
}
@Override
public void run() {
// TODO Auto-generated method stub
}
} |
Partager