package myanez.assign4;

import java.awt.*;
import java.awt.image.*;
import java.applet.*;
import jotsa.*;



public class multipleQueues extends Thread {
   String Name;
   int i;
   int holder;
   processScheduling Ap;

   multipleQueues(processScheduling Ap, String Name){
      this.Name = Name;
      this. Ap = Ap;
   }

   public void run(){

      try {sleep(5000);}
      catch (InterruptedException e) {stop();}
      
      Ap.counter = 1;
      for (i = 0; i < 5; i++) {
         Ap.nextObjectToBeMoved = Ap.processes[0];
         holder = Ap.nextObjectToBeMoved;
         Ap.scriptField.setText(">>> Scheduling first process in queue to the CPU");
         Ap.FIFOAnimation();
         try {sleep(Ap.move_time);}
         catch (InterruptedException e) {stop();}

         Ap.FIFOmoveRest();
         Ap.scriptField.setText(">>> Updating the queue");
         try {sleep(Ap.move_time);}
         catch (InterruptedException e) {stop();}
         Ap. counter++;

         if(Ap.nextObjectToBeMoved == 0){
         try {sleep(Ap.move_zero);}
         catch (InterruptedException e) {stop();}
         }
         if(Ap.nextObjectToBeMoved == 1){
         try {sleep(Ap.move_one);}
         catch (InterruptedException e) {stop();}
         }
         if(Ap.nextObjectToBeMoved == 2){
         try {sleep(Ap.move_two);}
         catch (InterruptedException e) {stop();}
         }
         if(Ap.nextObjectToBeMoved == 3){
         try {sleep(Ap.move_three);}
         catch (InterruptedException e) {stop();}
         }
         if(Ap.nextObjectToBeMoved == 4){
         try {sleep(Ap.move_four);}
         catch (InterruptedException e) {stop();}
         }

 
         if(holder == 0)
           Ap.obj0.set_remove_time();
         if(holder == 1)
           Ap.obj1.set_remove_time();
         if(holder == 2)
           Ap.obj2.set_remove_time();
         if(holder == 3)
           Ap.obj3.set_remove_time();
         if(holder == 4)
           Ap.obj4.set_remove_time();
 
       } 
      
      try {sleep(Ap.move_time);}
      catch (InterruptedException e) {stop();}

      Ap.obj21.reset_color(Color.red);
      Ap.x7[0] = 660;
      Ap.x7[1] = 835;  /* 835 200 for cpu circle */
      Ap.y7[0] = 80;
      Ap.y7[1] = 200;
      Ap.obj21.path_poly_set(Ap.x7,Ap.y7,Ap.time);

      Ap.x6[0] = 600;
      Ap.x6[1] = 660;  /* 835 200 for cpu circle */
      Ap.y6[0] = 80;
      Ap.y6[1] = 80;
      Ap.obj11.path_poly_set(Ap.x6,Ap.y6,Ap.time);

      Ap.x5[0] = 540;
      Ap.x5[1] = 600;  /* 835 200 for cpu circle */
      Ap.y5[0] = 80;
      Ap.y5[1] = 80;
      Ap.obj01.path_poly_set(Ap.x5,Ap.y5,Ap.time);

      Ap.JotsaInsertObject(Ap.obj01);
      Ap.obj01.activate_delay();
      Ap.JotsaInsertObject(Ap.obj11);
      Ap.obj11.activate_delay();
      Ap.JotsaInsertObject(Ap.obj21);
      Ap.obj21.activate_delay();
      try {sleep(Ap.move_time);}
      catch (InterruptedException e) {stop();}
      Ap.obj21.set_remove_time();

      try {sleep(Ap.move_time);}
      catch (InterruptedException e) {stop();}
      Ap.x6[0] = 660;
      Ap.x6[1] = 835;  /* 835 200 for cpu circle */
      Ap.y6[0] = 80; 
      Ap.y6[1] = 200;
      Ap.obj11.path_poly_set(Ap.x6,Ap.y6,Ap.time);
      Ap.obj11.reset_color(Color.red);
 
      Ap.x5[0] = 600;
      Ap.x5[1] = 660;  /* 835 200 for cpu circle */
      Ap.y5[0] = 80; 
      Ap.y5[1] = 80;
      Ap.obj01.path_poly_set(Ap.x5,Ap.y5,Ap.time);
 
      Ap.JotsaInsertObject(Ap.obj01);
      Ap.obj01.activate_delay();
      Ap.JotsaInsertObject(Ap.obj11);
      Ap.obj11.activate_delay();
      try {sleep(Ap.move_time);}
      catch (InterruptedException e) {stop();}
      Ap.obj11.set_remove_time();

     /*third process to cpu */ 
      Ap.x5[0] = 660;
      Ap.x5[1] = 835;  /* 835 200 for cpu circle */
      Ap.y5[0] = 80; 
      Ap.y5[1] = 200;
      Ap.obj01.reset_color(Color.red);
      Ap.obj01.path_poly_set(Ap.x5,Ap.y5,Ap.time);
      Ap.JotsaInsertObject(Ap.obj01);
      Ap.obj01.activate_delay();
      
      
      /* pro with high priority */
      Ap.x6[0] = 80;
      Ap.x6[1] = 660;  /* 835 200 for cpu circle */
      Ap.y6[0] = 250; 
      Ap.y6[1] = 200;
      Ap.obj81.path_poly_set(Ap.x6,Ap.y6,Ap.time);
      Ap.JotsaInsertObject(Ap.obj81);
      Ap.obj81.activate_delay();
      try {sleep(Ap.move_time);}
      catch (InterruptedException e) {stop();}

      Ap.x6[0] = 660;
      Ap.x6[1] = 835;  /* 835 200 for cpu circle */
      Ap.y6[0] = 200;
      Ap.y6[1] = 200;
      Ap.obj81.reset_color(Color.red);
      Ap.obj81.path_poly_set(Ap.x6,Ap.y6,Ap.time);
      Ap.JotsaInsertObject(Ap.obj81);
      Ap.obj81.activate_delay(); 
      try {sleep(Ap.move_time);}
      catch (InterruptedException e) {stop();}

      Ap.x5[0] = 835;
      Ap.x5[1] = 660;  /* 835 200 for cpu circle */
      Ap.y5[0] = 200;
      Ap.y5[1] = 80;
      Ap.obj01.reset_color(Color.blue);
      Ap.obj01.path_poly_set(Ap.x5,Ap.y5,Ap.time);
      Ap.JotsaInsertObject(Ap.obj01);
      Ap.obj01.activate_delay(); 
      try {sleep(Ap.move_time);}
      catch (InterruptedException e) {stop();}
      Ap.obj81.set_remove_time();
 
      Ap.x5[0] = 660;
      Ap.x5[1] = 835;  /* 835 200 for cpu circle */
      Ap.y5[0] = 80;
      Ap.y5[1] = 200;
      Ap.obj01.reset_color(Color.red);
      Ap.obj01.path_poly_set(Ap.x5,Ap.y5,Ap.time);
      Ap.JotsaInsertObject(Ap.obj01);
      Ap.obj01.activate_delay(); 
      try {sleep(Ap.move_time);}
      catch (InterruptedException e) {stop();}
      Ap.obj01.set_remove_time();

  /* last queue */
      Ap.x6[0] = 660;
      Ap.x6[1] = 835;  /* 835 200 for cpu circle */
      Ap.y6[0] = 320;
      Ap.y6[1] = 200;
      Ap.obj41.path_poly_set(Ap.x6,Ap.y6,Ap.time);

      Ap.x5[0] = 600;
      Ap.x5[1] = 660;  /* 835 200 for cpu circle */
      Ap.y5[0] = 320;
      Ap.y5[1] = 320;
      Ap.obj31.path_poly_set(Ap.x5,Ap.y5,Ap.time);
 
      Ap.obj41.reset_color(Color.red);
      Ap.JotsaInsertObject(Ap.obj31);
      Ap.obj31.activate_delay();
      Ap.JotsaInsertObject(Ap.obj41);
      Ap.obj41.activate_delay();
      try {sleep(Ap.move_time);}
      catch (InterruptedException e) {stop();}
      Ap.obj41.set_remove_time();

      Ap.x6[0] = 660; 
      Ap.x6[1] = 835;  /* 835 200 for cpu circle */ 
      Ap.y6[0] = 320; 
      Ap.y6[1] = 200; 
      Ap.obj31.reset_color(Color.red);
      Ap.obj31.path_poly_set(Ap.x6,Ap.y6,Ap.time); 
      Ap.JotsaInsertObject(Ap.obj31); 
      Ap.obj31.activate_delay(); 
      try {sleep(Ap.move_time);} 
      catch (InterruptedException e) {stop();} 
      Ap.obj31.set_remove_time(); 
 
      Ap.set_display();
      Ap.Process.enable();
      stop();
   }
}

