/**
  * **************** Attempts to run the computer for 1 clock cycle. Asks the current scheduler for
  * which process to run, attempts to tick() that process.
  */
 public void tick() {
   int completedcounter = 0;
   int turnaround = 0;
   for (Process p : gProcList) {
     if (p.getBeginTime() == gTicks) {
       gCurrentScheduler.add(p);
     }
     if (p.isFinished()) {
       completedcounter++;
       turnaround += (p.getEndTime() - p.getBeginTime());
     }
   }
   Process p = gCurrentScheduler.getNext();
   if (p == null) {
     gGraphicsComp.setTime(gTicks, Process.SYSTEM_PROCESS);
     Process.SYSTEM_PROCESS.tick();
     gTicks++;
     gStatsComp.setTicks(gTicks);
     gStatsComp.setNumJobsFinished(completedcounter);
     gStatsComp.setTurnaround(
         completedcounter == 0 ? 0 : (double) turnaround / (double) completedcounter);
     gStatsComp.setThroughput((double) completedcounter * 100.0 / (double) gTicks);
     gStatsComp.setCPUUtilization(
         100.0 * (double) (gTicks - Process.SYSTEM_PROCESS.getTicks()) / (double) gTicks);
     gParentWindow.halt();
   } else {
     if (gPreviousProc != null && !p.equals(gPreviousProc)) {
       gGraphicsComp.setTime(gTicks, Process.SYSTEM_PROCESS);
       Process.SYSTEM_PROCESS.tick();
     } else {
       p.tick();
       gGraphicsComp.setTime(gTicks, p);
     }
     gTicks++;
     if (p.isFinished()) {
       p.setEndTime(gTicks);
     }
     gStatsComp.setTicks(gTicks);
     gStatsComp.setNumJobsFinished(completedcounter);
     gStatsComp.setTurnaround(
         completedcounter == 0 ? 0 : (double) turnaround / (double) completedcounter);
     gStatsComp.setThroughput((double) completedcounter * 100.0 / (double) gTicks);
     gStatsComp.setCPUUtilization(
         100.0 * (double) (gTicks - Process.SYSTEM_PROCESS.getTicks()) / (double) gTicks);
     gPreviousProc = p;
   }
 }
 /** ***************** Resets the graphics, lists, processes, stats, etc. */
 public void reset() {
   if (gFile != null) {
     try {
       loadFile(gFile);
     } catch (FileNotFoundException e) {
       e.printStackTrace();
     }
   } else {
     gProcList.clear();
     gPreviousProc = null;
     gParentWindow.halt();
     gCurrentScheduler.clear();
     gTicks = 0;
     gGraphicsComp.init();
     gStatsComp.init();
     Process.SYSTEM_PROCESS.reset();
   }
 }
 /**
  * ****************** Loads a file as a process list
  *
  * @param mFile the file to load
  * @throws FileNotFoundException
  */
 public void loadFile(File mFile) throws FileNotFoundException {
   gProcList.clear();
   gPreviousProc = null;
   gParentWindow.halt();
   gCurrentScheduler.clear();
   gTicks = 0;
   gGraphicsComp.init();
   gStatsComp.init();
   Process.SYSTEM_PROCESS.reset();
   gFile = mFile;
   Scanner tScanner = new Scanner(gFile);
   while (tScanner.hasNextLine()) {
     String tmp = tScanner.nextLine();
     if (tmp.length() > 0 && tmp.charAt(0) != '#') {
       try {
         gProcList.add(new Process(tmp));
       } catch (RuntimeException e) {
         System.err.println(e.getMessage());
       }
     }
     gGraphicsComp.setProcList(gProcList);
   }
 }