├── src └── main │ ├── classes │ ├── manifest.txt │ ├── Job.class │ ├── Node.class │ ├── Stack.class │ ├── Scheduler.class │ ├── FCFSPolicy.class │ ├── SchedulingGUI.jar │ ├── TitleThread.class │ ├── AbsoluteLayout.class │ ├── CPUScheduler.class │ ├── CalcSimulation.class │ ├── PriorityPolicy.class │ ├── SchedulingGUI.class │ ├── MaxPriorityQueue.class │ ├── RoundRobinPolicy.class │ ├── SchedulingGUI$1.class │ ├── SchedulingGUI$2.class │ ├── SchedulingGUI$3.class │ ├── SchedulingGUI$4.class │ ├── AbsoluteConstraints.class │ ├── ComputationThread.class │ ├── src │ │ └── main │ │ │ └── java │ │ │ ├── dark-abstract2.jpg │ │ │ └── dark-abstract-tech-background_53876-90630.jpg │ └── SchedulingGUI$WindowListener.class │ └── java │ ├── planning.ico │ ├── dark-abstract2.jpg │ ├── dark-abstract-tech-background_53876-90630.jpg │ ├── Node.java │ ├── Scheduler.java │ ├── Job.java │ ├── TitleThread.java │ ├── Stack.java │ ├── RoundRobinPolicy.java │ ├── FCFSPolicy.java │ ├── PriorityPolicy.java │ ├── MaxPriorityQueue.java │ ├── ComputationThread.java │ ├── AbsoluteConstraints.java │ ├── AbsoluteLayout.java │ ├── CPUScheduler.java │ ├── SchedulingGUI.java │ ├── SchedulingGUI.form │ ├── CalcSimulation.java │ └── CalcSimulation.form ├── target ├── maven-status │ └── maven-compiler-plugin │ │ ├── testCompile │ │ └── default-testCompile │ │ │ └── inputFiles.lst │ │ └── compile │ │ └── default-compile │ │ ├── createdFiles.lst │ │ └── inputFiles.lst ├── classes │ ├── Job.class │ ├── Node.class │ ├── Stack.class │ ├── FCFSPolicy.class │ ├── Scheduler.class │ ├── TitleThread.class │ ├── CPUScheduler.class │ ├── SchedulingGUI.class │ ├── AbsoluteLayout.class │ ├── CalcSimulation.class │ ├── MaxPriorityQueue.class │ ├── PriorityPolicy.class │ ├── RoundRobinPolicy.class │ ├── SchedulingGUI$1.class │ ├── SchedulingGUI$2.class │ ├── SchedulingGUI$3.class │ ├── SchedulingGUI$4.class │ ├── ComputationThread.class │ ├── AbsoluteConstraints.class │ └── SchedulingGUI$WindowListener.class ├── CPUSchedulingSimulation-1.0-SNAPSHOT.jar └── maven-archiver │ └── pom.properties ├── sources └── blank.jpg ├── .idea ├── misc.xml ├── modules.xml ├── libraries │ └── CPUSchedulingSimulation_1_0_SNAPSHOT.xml └── workspace.xml ├── CPUSchedulingSimulation.iml ├── pom.xml └── README.md /src/main/classes/manifest.txt: -------------------------------------------------------------------------------- 1 | Main-Class: SchedulingGUI 2 | -------------------------------------------------------------------------------- /target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sources/blank.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/sources/blank.jpg -------------------------------------------------------------------------------- /target/classes/Job.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/target/classes/Job.class -------------------------------------------------------------------------------- /src/main/classes/Job.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/src/main/classes/Job.class -------------------------------------------------------------------------------- /src/main/classes/Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/src/main/classes/Node.class -------------------------------------------------------------------------------- /src/main/java/planning.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/src/main/java/planning.ico -------------------------------------------------------------------------------- /target/classes/Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/target/classes/Node.class -------------------------------------------------------------------------------- /target/classes/Stack.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/target/classes/Stack.class -------------------------------------------------------------------------------- /src/main/classes/Stack.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/src/main/classes/Stack.class -------------------------------------------------------------------------------- /src/main/classes/Scheduler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/src/main/classes/Scheduler.class -------------------------------------------------------------------------------- /src/main/java/dark-abstract2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/src/main/java/dark-abstract2.jpg -------------------------------------------------------------------------------- /target/classes/FCFSPolicy.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/target/classes/FCFSPolicy.class -------------------------------------------------------------------------------- /target/classes/Scheduler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/target/classes/Scheduler.class -------------------------------------------------------------------------------- /target/classes/TitleThread.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/target/classes/TitleThread.class -------------------------------------------------------------------------------- /src/main/classes/FCFSPolicy.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/src/main/classes/FCFSPolicy.class -------------------------------------------------------------------------------- /src/main/classes/SchedulingGUI.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/src/main/classes/SchedulingGUI.jar -------------------------------------------------------------------------------- /src/main/classes/TitleThread.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/src/main/classes/TitleThread.class -------------------------------------------------------------------------------- /target/classes/CPUScheduler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/target/classes/CPUScheduler.class -------------------------------------------------------------------------------- /target/classes/SchedulingGUI.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/target/classes/SchedulingGUI.class -------------------------------------------------------------------------------- /src/main/classes/AbsoluteLayout.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/src/main/classes/AbsoluteLayout.class -------------------------------------------------------------------------------- /src/main/classes/CPUScheduler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/src/main/classes/CPUScheduler.class -------------------------------------------------------------------------------- /src/main/classes/CalcSimulation.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/src/main/classes/CalcSimulation.class -------------------------------------------------------------------------------- /src/main/classes/PriorityPolicy.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/src/main/classes/PriorityPolicy.class -------------------------------------------------------------------------------- /src/main/classes/SchedulingGUI.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/src/main/classes/SchedulingGUI.class -------------------------------------------------------------------------------- /target/classes/AbsoluteLayout.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/target/classes/AbsoluteLayout.class -------------------------------------------------------------------------------- /target/classes/CalcSimulation.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/target/classes/CalcSimulation.class -------------------------------------------------------------------------------- /target/classes/MaxPriorityQueue.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/target/classes/MaxPriorityQueue.class -------------------------------------------------------------------------------- /target/classes/PriorityPolicy.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/target/classes/PriorityPolicy.class -------------------------------------------------------------------------------- /target/classes/RoundRobinPolicy.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/target/classes/RoundRobinPolicy.class -------------------------------------------------------------------------------- /target/classes/SchedulingGUI$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/target/classes/SchedulingGUI$1.class -------------------------------------------------------------------------------- /target/classes/SchedulingGUI$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/target/classes/SchedulingGUI$2.class -------------------------------------------------------------------------------- /target/classes/SchedulingGUI$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/target/classes/SchedulingGUI$3.class -------------------------------------------------------------------------------- /target/classes/SchedulingGUI$4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/target/classes/SchedulingGUI$4.class -------------------------------------------------------------------------------- /src/main/classes/MaxPriorityQueue.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/src/main/classes/MaxPriorityQueue.class -------------------------------------------------------------------------------- /src/main/classes/RoundRobinPolicy.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/src/main/classes/RoundRobinPolicy.class -------------------------------------------------------------------------------- /src/main/classes/SchedulingGUI$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/src/main/classes/SchedulingGUI$1.class -------------------------------------------------------------------------------- /src/main/classes/SchedulingGUI$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/src/main/classes/SchedulingGUI$2.class -------------------------------------------------------------------------------- /src/main/classes/SchedulingGUI$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/src/main/classes/SchedulingGUI$3.class -------------------------------------------------------------------------------- /src/main/classes/SchedulingGUI$4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/src/main/classes/SchedulingGUI$4.class -------------------------------------------------------------------------------- /target/classes/ComputationThread.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/target/classes/ComputationThread.class -------------------------------------------------------------------------------- /src/main/classes/AbsoluteConstraints.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/src/main/classes/AbsoluteConstraints.class -------------------------------------------------------------------------------- /src/main/classes/ComputationThread.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/src/main/classes/ComputationThread.class -------------------------------------------------------------------------------- /target/classes/AbsoluteConstraints.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/target/classes/AbsoluteConstraints.class -------------------------------------------------------------------------------- /target/CPUSchedulingSimulation-1.0-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/target/CPUSchedulingSimulation-1.0-SNAPSHOT.jar -------------------------------------------------------------------------------- /src/main/classes/src/main/java/dark-abstract2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/src/main/classes/src/main/java/dark-abstract2.jpg -------------------------------------------------------------------------------- /target/classes/SchedulingGUI$WindowListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/target/classes/SchedulingGUI$WindowListener.class -------------------------------------------------------------------------------- /src/main/classes/SchedulingGUI$WindowListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/src/main/classes/SchedulingGUI$WindowListener.class -------------------------------------------------------------------------------- /target/maven-archiver/pom.properties: -------------------------------------------------------------------------------- 1 | #Generated by Maven 2 | #Thu Jun 10 00:16:15 PKT 2021 3 | groupId=com.mycompany 4 | artifactId=CPUSchedulingSimulation 5 | version=1.0-SNAPSHOT 6 | -------------------------------------------------------------------------------- /src/main/java/dark-abstract-tech-background_53876-90630.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/src/main/java/dark-abstract-tech-background_53876-90630.jpg -------------------------------------------------------------------------------- /src/main/java/Node.java: -------------------------------------------------------------------------------- 1 | public class Node { 2 | Node next; 3 | Job job; 4 | 5 | Node(Job job) { 6 | this.job = job; 7 | next = null; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/classes/src/main/java/dark-abstract-tech-background_53876-90630.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ammarlodhi255/cpu-scheduling-simulator/HEAD/src/main/classes/src/main/java/dark-abstract-tech-background_53876-90630.jpg -------------------------------------------------------------------------------- /src/main/java/Scheduler.java: -------------------------------------------------------------------------------- 1 | public interface Scheduler { 2 | public void allocateCPU(Job job); 3 | public Job dequeue(); 4 | public void enqueue(Job job); 5 | public String getRemainingProcesses(); 6 | public boolean isEmpty(); 7 | public Node peek(); 8 | } 9 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/libraries/CPUSchedulingSimulation_1_0_SNAPSHOT.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /CPUSchedulingSimulation.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst: -------------------------------------------------------------------------------- 1 | TitleThread.class 2 | CalcSimulation.class 3 | FCFSSelected$2.class 4 | Scheduler.class 5 | SchedulingGUI$1.class 6 | SchedulingGUI$3.class 7 | FCFSSelected$1.class 8 | ComputationThread.class 9 | MaxPriorityQueue.class 10 | CPUScheduler.class 11 | SchedulingGUI$4.class 12 | Node.class 13 | FCFSPolicy.class 14 | PriorityPolicy.class 15 | Job.class 16 | SchedulingGUI$5.class 17 | FCFSSelected.class 18 | SchedulingGUI$WindowListener.class 19 | SchedulingGUI.class 20 | RoundRobinPolicy.class 21 | SchedulingGUI$2.class 22 | -------------------------------------------------------------------------------- /src/main/java/Job.java: -------------------------------------------------------------------------------- 1 | import javax.swing.*; 2 | 3 | public class Job { 4 | long burstTime; 5 | long arrivalTime; 6 | String processID; 7 | long startTime; 8 | long endTime; 9 | long waitTime; 10 | JProgressBar progressBar; 11 | JLabel burstTimeLabel; 12 | int lastRemainingBurst; 13 | JLabel waitTimeLabel; 14 | int pBarValue = 0; 15 | int priority; 16 | 17 | public Job(String processID, long arrivalTime, long burstTime, long startTime) { 18 | this.processID = processID; 19 | this.arrivalTime = arrivalTime; 20 | this.burstTime = burstTime; 21 | this.startTime = startTime; 22 | lastRemainingBurst = (int) burstTime; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/TitleThread.java: -------------------------------------------------------------------------------- 1 | 2 | import javax.swing.JLabel; 3 | 4 | public class TitleThread extends Thread { 5 | String text; 6 | JLabel label; 7 | long sleepTime; 8 | 9 | TitleThread(String text, JLabel label, long time) { 10 | this.label = label; 11 | this.text = text; 12 | sleepTime = time; 13 | } 14 | 15 | public void run() { 16 | String str = new String(); 17 | for(int i = 0; i < text.length(); i++) { 18 | str += text.charAt(i) + ""; 19 | label.setText(str); 20 | try { 21 | Thread.sleep(sleepTime); 22 | } catch(InterruptedException ex) {} 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | com.mycompany 5 | CPUSchedulingSimulation 6 | 1.0-SNAPSHOT 7 | jar 8 | 9 | 10 | org.netbeans.external 11 | AbsoluteLayout 12 | RELEASE121 13 | 14 | 15 | 16 | UTF-8 17 | 15 18 | 15 19 | 20 | -------------------------------------------------------------------------------- /target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst: -------------------------------------------------------------------------------- 1 | D:\Programming Files\CPUSchedulingSimulation\src\main\java\PriorityPolicy.java 2 | D:\Programming Files\CPUSchedulingSimulation\src\main\java\CPUScheduler.java 3 | D:\Programming Files\CPUSchedulingSimulation\src\main\java\Node.java 4 | D:\Programming Files\CPUSchedulingSimulation\src\main\java\MaxPriorityQueue.java 5 | D:\Programming Files\CPUSchedulingSimulation\src\main\java\FCFSPolicy.java 6 | D:\Programming Files\CPUSchedulingSimulation\src\main\java\FCFSSelected.java 7 | D:\Programming Files\CPUSchedulingSimulation\src\main\java\Job.java 8 | D:\Programming Files\CPUSchedulingSimulation\src\main\java\SchedulingGUI.java 9 | D:\Programming Files\CPUSchedulingSimulation\src\main\java\Scheduler.java 10 | D:\Programming Files\CPUSchedulingSimulation\src\main\java\TitleThread.java 11 | D:\Programming Files\CPUSchedulingSimulation\src\main\java\CalcSimulation.java 12 | D:\Programming Files\CPUSchedulingSimulation\src\main\java\RoundRobinPolicy.java 13 | D:\Programming Files\CPUSchedulingSimulation\src\main\java\ComputationThread.java 14 | -------------------------------------------------------------------------------- /.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 1623491532844 25 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/main/java/Stack.java: -------------------------------------------------------------------------------- 1 | 2 | import java.io.BufferedReader; 3 | import java.io.File; 4 | import java.io.FileReader; 5 | import javax.swing.JOptionPane; 6 | 7 | // Stack implementation with Singly Linked List: 8 | class Stack implements Scheduler { 9 | private Node top; 10 | Stack() { top = null; } 11 | File sourceFile; 12 | 13 | Stack(File sourceFile) { 14 | this.sourceFile = sourceFile; 15 | top = null; 16 | } 17 | 18 | public boolean isEmpty() { return top == null; } 19 | 20 | public Node peek() { 21 | if(isEmpty()) 22 | throw new RuntimeException("StackUnderFlow"); 23 | return top; 24 | } 25 | 26 | public void enqueue(Job job) { 27 | Node newest = new Node(job); 28 | if(isEmpty()) top = newest; 29 | else { 30 | newest.next = top; 31 | top = newest; 32 | } 33 | } 34 | 35 | public Job dequeue() { 36 | if(isEmpty()) 37 | throw new RuntimeException("StackUnderflow"); 38 | Job data = top.job; 39 | top = top.next; 40 | return data; 41 | } 42 | 43 | public String getRemainingProcesses() { 44 | Node trav = top; 45 | String rem = new String(); 46 | if(isEmpty()) return ""; 47 | else { 48 | while(trav != null) { 49 | rem += trav.job.processID + " "; 50 | trav = trav.next; 51 | } 52 | } 53 | return rem; 54 | } 55 | 56 | public void allocateCPU(Job job) { 57 | try { 58 | BufferedReader bufReader = new BufferedReader(new FileReader(sourceFile)); 59 | String str = new String(); 60 | while((str = bufReader.readLine()) != null) { 61 | 62 | } 63 | 64 | String remProcesses = getRemainingProcesses(); 65 | } catch(Exception ex) { 66 | JOptionPane.showMessageDialog(null, "IO Error"); 67 | return; 68 | } 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /src/main/java/RoundRobinPolicy.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import javax.swing.*; 3 | 4 | public class RoundRobinPolicy implements Scheduler { 5 | static final long TIME_QUANTUM = 140; // quantum of time is set to 150s 6 | File sourceFile; 7 | 8 | RoundRobinPolicy(File sourceFile) { 9 | this.sourceFile = sourceFile; 10 | } 11 | 12 | Node head = null; 13 | Node tail = null; 14 | 15 | public void enqueue(Job job) { 16 | Node newNode = new Node(job); 17 | if(isEmpty()) { 18 | head = tail = newNode; 19 | } else { 20 | tail.next = newNode; 21 | tail = tail.next; 22 | } 23 | } 24 | 25 | public void allocateCPU(Job job) { 26 | 27 | try { 28 | BufferedReader bufReader = new BufferedReader(new FileReader(sourceFile)); 29 | String str = new String(); 30 | while((str = bufReader.readLine()) != null) { 31 | 32 | } 33 | 34 | String remProcesses = getRemainingProcesses(); 35 | } catch(Exception ex) { 36 | JOptionPane.showMessageDialog(null, "IO Error"); 37 | return; 38 | } 39 | } 40 | 41 | public Job dequeue() { 42 | if(isEmpty()) { 43 | return null; 44 | } else { 45 | Job tempJob = head.job; 46 | head = head.next; 47 | tempJob.waitTime = System.nanoTime() - tempJob.startTime; 48 | return tempJob; 49 | } 50 | } 51 | 52 | public boolean isEmpty() { 53 | return head == null; 54 | } 55 | 56 | public String getRemainingProcesses() { 57 | Node trav = head; 58 | String rem = new String(); 59 | if(isEmpty()) return ""; 60 | else { 61 | while(trav != null) { 62 | rem += trav.job.processID + " "; 63 | trav = trav.next; 64 | } 65 | } 66 | return rem; 67 | } 68 | 69 | public Node peek() { 70 | return head; 71 | } 72 | } -------------------------------------------------------------------------------- /src/main/java/FCFSPolicy.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import javax.swing.JOptionPane; 3 | 4 | public class FCFSPolicy implements Scheduler { 5 | File sourceFile; 6 | Node head, tail; 7 | 8 | FCFSPolicy(File sourceFile) { 9 | this.sourceFile = sourceFile; 10 | head = tail = null; 11 | } 12 | 13 | public boolean isEmpty() { return head == null; } 14 | 15 | public void enqueue(Job job) { 16 | Node newNode = new Node(job); 17 | if(isEmpty()) { 18 | head = tail = newNode; 19 | } else { 20 | tail.next = newNode; 21 | tail = tail.next; 22 | } 23 | } 24 | 25 | public Job dequeue() { 26 | if(isEmpty()) { 27 | return null; 28 | } else { 29 | Job tempJob = head.job; 30 | head = head.next; 31 | tempJob.waitTime = System.nanoTime() - tempJob.startTime; 32 | return tempJob; 33 | } 34 | } 35 | 36 | public void allocateCPU(Job job) { 37 | try { 38 | BufferedReader bufReader = new BufferedReader(new FileReader(sourceFile)); 39 | String str = new String(); 40 | while((str = bufReader.readLine()) != null) { 41 | 42 | } 43 | 44 | String remProcesses = getRemainingProcesses(); 45 | } catch(Exception ex) { 46 | JOptionPane.showMessageDialog(null, "IO Error"); 47 | return; 48 | } 49 | } 50 | 51 | public void enqueueAtHead(Job job) { 52 | Node newNode = new Node(job); 53 | if(isEmpty()) head = newNode; 54 | else { 55 | Node temp = head; 56 | head = newNode; 57 | head.next = temp; 58 | } 59 | } 60 | 61 | public Node peek() { 62 | return head; 63 | } 64 | 65 | public String getRemainingProcesses() { 66 | Node trav = head; 67 | String rem = new String(); 68 | if(isEmpty()) return ""; 69 | else { 70 | while(trav != null) { 71 | rem += trav.job.processID + " "; 72 | trav = trav.next; 73 | } 74 | } 75 | return rem; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/PriorityPolicy.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import javax.swing.JOptionPane; 3 | 4 | public class PriorityPolicy implements Scheduler { 5 | File sourceFile; 6 | Node head, tail; 7 | 8 | PriorityPolicy(File sourceFile) { 9 | this.sourceFile = sourceFile; 10 | head = tail = null; 11 | } 12 | 13 | public boolean isEmpty() { return head == null; } 14 | 15 | public void enqueue(Job job) { 16 | Node newNode = new Node(job); 17 | if(isEmpty()) { 18 | head = tail = newNode; 19 | } else { 20 | tail.next = newNode; 21 | tail = tail.next; 22 | } 23 | } 24 | 25 | public Job dequeue() { 26 | if(isEmpty()) { 27 | return null; 28 | } else { 29 | Job tempJob = head.job; 30 | head = head.next; 31 | tempJob.waitTime = System.nanoTime() - tempJob.startTime; 32 | return tempJob; 33 | } 34 | } 35 | 36 | public void allocateCPU(Job job) { 37 | try { 38 | BufferedReader bufReader = new BufferedReader(new FileReader(sourceFile)); 39 | String str = new String(); 40 | while((str = bufReader.readLine()) != null) { 41 | 42 | } 43 | 44 | String remProcesses = getRemainingProcesses(); 45 | } catch(Exception ex) { 46 | JOptionPane.showMessageDialog(null, "IO Error"); 47 | return; 48 | } 49 | } 50 | 51 | public void enqueueAtHead(Job job) { 52 | Node newNode = new Node(job); 53 | if(isEmpty()) head = newNode; 54 | else { 55 | Node temp = head; 56 | head = newNode; 57 | head.next = temp; 58 | } 59 | } 60 | 61 | public Node peek() { 62 | return head; 63 | } 64 | 65 | public String getRemainingProcesses() { 66 | Node trav = head; 67 | String rem = new String(); 68 | if(isEmpty()) return ""; 69 | else { 70 | while(trav != null) { 71 | rem += trav.job.processID + " "; 72 | trav = trav.next; 73 | } 74 | } 75 | return rem; 76 | } 77 | } 78 | 79 | -------------------------------------------------------------------------------- /src/main/java/MaxPriorityQueue.java: -------------------------------------------------------------------------------- 1 | public class MaxPriorityQueue { 2 | private Job[] arr; 3 | private int current = -1; 4 | 5 | MaxPriorityQueue() { arr = new Job[10]; } 6 | 7 | public int capacity() { return arr.length; } 8 | public int size() { return current + 1; } 9 | public boolean isEmpty() { return size() == 0; } 10 | 11 | // Worst case: O(n), Avg ~O(1) 12 | public void insert(Job job) { 13 | if(size() == capacity()) { 14 | Job[] newArr = new Job[capacity() * 2]; 15 | for(int i = 0; i < size(); i++) 16 | newArr[i] = arr[i]; 17 | arr = newArr; 18 | } 19 | arr[++current] = job; 20 | } 21 | 22 | // Worst case: O(n) 23 | public Job extractMax() { 24 | Job max = getMax(); 25 | removeAt(getIndex(max)); 26 | return max; 27 | } 28 | 29 | // Worst case: O(n) 30 | public Job getMax() { 31 | if(isEmpty()) 32 | throw new RuntimeException("Error: "); 33 | Job max = arr[0]; 34 | for(int i = 1; i < size(); i++) { 35 | if(arr[i].priority > max.priority) 36 | max = arr[i]; 37 | } 38 | return max; 39 | } 40 | 41 | // Worst case: O(n) 42 | private int getIndex(Job job) { 43 | if(!contains(job)) 44 | throw new RuntimeException("Error: <" + job.processID + " no such data in priority queue>"); 45 | for(int i = 0; i < size(); i++) 46 | if(arr[i] == job) return i; 47 | return -1; 48 | } 49 | 50 | // Worst case: O(n) 51 | public boolean contains(Job job) { 52 | if(isEmpty()) 53 | throw new RuntimeException("Error: "); 54 | for(Job j : arr) 55 | if(j == job) return true; 56 | return false; 57 | } 58 | 59 | // Worst case: O(n), Avg ~O(log(n)) 60 | public void removeAt(int index) { 61 | if(isEmpty()) 62 | throw new RuntimeException("Error: "); 63 | for(int i = index; i < size(); i++) { 64 | if(i != size() - 1) 65 | arr[i] = arr[i+1]; 66 | } 67 | --current; 68 | } 69 | 70 | // Worst case: O(1) 71 | public int getPriority(int index) { 72 | if(index >= size() || index < 0) 73 | throw new RuntimeException("Error: "); 74 | return arr[index].priority; 75 | } 76 | 77 | } -------------------------------------------------------------------------------- /src/main/java/ComputationThread.java: -------------------------------------------------------------------------------- 1 | import javax.swing.*; 2 | 3 | public class ComputationThread implements Runnable { 4 | Scheduler policy; 5 | Thread t; 6 | Job job; 7 | JTextField textField; 8 | JTextArea readyQueue; 9 | JProgressBar pbar; 10 | JLabel burstTime; 11 | 12 | ComputationThread(Job job, Scheduler policy, JTextArea readyQueue, JTextField textField, 13 | JProgressBar pbar, JLabel burstTime) { 14 | this.policy = policy; 15 | t = new Thread(this); 16 | this.job = job; 17 | this.readyQueue = readyQueue; 18 | this.textField = textField; 19 | this.pbar = pbar; 20 | this.burstTime = burstTime; 21 | } 22 | 23 | public void assignJob(Job job) { 24 | this.job = job; 25 | } 26 | 27 | public void run() { 28 | policy.allocateCPU(job); 29 | boolean status = true; 30 | 31 | if(CalcSimulation.algo.equals("FCFS") || CalcSimulation.algo.equals("Priority Scheduling") 32 | || CalcSimulation.algo.equals("Shortest Job First")) { 33 | int min = 0; 34 | int max = (int) job.burstTime; 35 | 36 | pbar.setMinimum(min); 37 | pbar.setMaximum(max); 38 | pbar.setValue(0); 39 | 40 | String remProcesses = policy.getRemainingProcesses(); 41 | readyQueue.setText(remProcesses); 42 | 43 | int remainingBurstTime = (int) job.burstTime; 44 | 45 | for(int i = 0; i < max; i++) { 46 | pbar.setValue(i); 47 | try { 48 | Thread.sleep(50); 49 | synchronized(this) { 50 | textField.setText(""); 51 | textField.setText(job.processID); 52 | } 53 | } catch(InterruptedException ex) {} 54 | remainingBurstTime--; 55 | burstTime.setText(String.valueOf(remainingBurstTime) + "ms"); 56 | } 57 | 58 | if(status) { 59 | CPUScheduler.statusSum++; 60 | System.out.println(CPUScheduler.statusSum); 61 | } 62 | } else if(CalcSimulation.algo.equals("Round Robin")) { 63 | int min = job.pBarValue; 64 | int max = (int) job.burstTime; 65 | 66 | pbar.setMinimum(0); 67 | pbar.setMaximum(max); 68 | 69 | int remainingBurstTime = (int) job.lastRemainingBurst; 70 | int exceedTime = 0; 71 | 72 | String remProcesses = policy.getRemainingProcesses(); 73 | readyQueue.setText(remProcesses); 74 | 75 | for(int i = min; i < max; i++) { 76 | pbar.setValue(i); 77 | try { 78 | Thread.sleep(50); 79 | 80 | if(exceedTime == RoundRobinPolicy.TIME_QUANTUM - 1 && remainingBurstTime > 0) { 81 | job.lastRemainingBurst = remainingBurstTime; 82 | job.pBarValue = i; 83 | policy.enqueue(job); 84 | break; 85 | } 86 | synchronized(this) { 87 | textField.setText(""); 88 | textField.setText(job.processID); 89 | } 90 | } catch(InterruptedException ex) {} 91 | remainingBurstTime--; 92 | burstTime.setText(String.valueOf(remainingBurstTime) + "ms"); 93 | exceedTime++; 94 | } 95 | 96 | readyQueue.setText(policy.getRemainingProcesses()); 97 | } 98 | 99 | job.endTime = System.nanoTime() - job.startTime; 100 | //remProcesses = policy.getRemainingProcesses(); 101 | // readyQueue.setText(remProcesses); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/AbsoluteConstraints.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | 21 | import java.awt.Dimension; 22 | import java.awt.Point; 23 | 24 | /** An object that encapsulates position and (optionally) size for 25 | * Absolute positioning of components. 26 | * 27 | * @see AbsoluteLayout 28 | * @version 1.01, Aug 19, 1998 29 | */ 30 | public class AbsoluteConstraints implements java.io.Serializable { 31 | /** generated Serialized Version UID */ 32 | static final long serialVersionUID = 5261460716622152494L; 33 | 34 | /** The X position of the component */ 35 | public int x; 36 | /** The Y position of the component */ 37 | public int y; 38 | /** The width of the component or -1 if the component's preferred width should be used */ 39 | public int width = -1; 40 | /** The height of the component or -1 if the component's preferred height should be used */ 41 | public int height = -1; 42 | 43 | /** Creates a new AbsoluteConstraints for specified position. 44 | * @param pos The position to be represented by this AbsoluteConstraints 45 | */ 46 | public AbsoluteConstraints(Point pos) { 47 | this (pos.x, pos.y); 48 | } 49 | 50 | /** Creates a new AbsoluteConstraints for specified position. 51 | * @param x The X position to be represented by this AbsoluteConstraints 52 | * @param y The Y position to be represented by this AbsoluteConstraints 53 | */ 54 | public AbsoluteConstraints(int x, int y) { 55 | this.x = x; 56 | this.y = y; 57 | } 58 | 59 | /** Creates a new AbsoluteConstraints for specified position and size. 60 | * @param pos The position to be represented by this AbsoluteConstraints 61 | * @param size The size to be represented by this AbsoluteConstraints or null 62 | * if the component's preferred size should be used 63 | */ 64 | public AbsoluteConstraints(Point pos, Dimension size) { 65 | this.x = pos.x; 66 | this.y = pos.y; 67 | if (size != null) { 68 | this.width = size.width; 69 | this.height = size.height; 70 | } 71 | } 72 | 73 | /** Creates a new AbsoluteConstraints for specified position and size. 74 | * @param x The X position to be represented by this AbsoluteConstraints 75 | * @param y The Y position to be represented by this AbsoluteConstraints 76 | * @param width The width to be represented by this AbsoluteConstraints or -1 if the 77 | * component's preferred width should be used 78 | * @param height The height to be represented by this AbsoluteConstraints or -1 if the 79 | * component's preferred height should be used 80 | */ 81 | public AbsoluteConstraints(int x, int y, int width, int height) { 82 | this.x = x; 83 | this.y = y; 84 | this.width = width; 85 | this.height = height; 86 | } 87 | 88 | /** @return The X position represented by this AbsoluteConstraints */ 89 | public int getX () { 90 | return x; 91 | } 92 | 93 | /** @return The Y position represented by this AbsoluteConstraints */ 94 | public int getY () { 95 | return y; 96 | } 97 | 98 | /** @return The width represented by this AbsoluteConstraints or -1 if the 99 | * component's preferred width should be used 100 | */ 101 | public int getWidth () { 102 | return width; 103 | } 104 | 105 | /** @return The height represented by this AbsoluteConstraints or -1 if the 106 | * component's preferred height should be used 107 | */ 108 | public int getHeight () { 109 | return height; 110 | } 111 | 112 | public String toString () { 113 | return super.toString () +" [x="+x+", y="+y+", width="+width+", height="+height+"]"; 114 | } 115 | 116 | } 117 | 118 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CPU-Scheduling-Simulator 2 | 3 | ## Table of Contents 4 | - [Overview](#overview) 5 | - [Problem Statement](#problem_statement) 6 | - [Features](#features) 7 | - [Files and Directories](#files-and-directories) 8 | - [Getting Started](#getting-started) 9 | - [Prerequisites](#prerequisites) 10 | - [Installation](#installation) 11 | - [Usage](#usage) 12 | - [Example](#example) 13 | - [Contributing](#contributing) 14 | - [YouTube Video](#youtube_video) 15 | 16 | ## Overview 17 | 18 | This repository contains a Java-based simulator for CPU scheduling algorithms. CPU scheduling is a fundamental aspect of operating systems, where the CPU decides the order in which processes are executed. This simulator allows users to visualize and analyze different scheduling algorithms such as First-Come, First-Served (FCFS), Shortest Job Next (SJN), Round Robin (RR), and more. 19 | 20 | ## Problem Statement 21 | Different CPU scheduling algorithms have unique properties, and choosing the right one for a particular situation depends on various criteria used to compare their performance. These criteria are referred to as CPU scheduling criteria. For instance, in some cases, maximizing response time may be prioritized over throughput, while in others, minimizing average waiting time might be more important, even if it means sacrificing response time. Sometimes, a balance between multiple criteria is required. The challenge lies in determining which scheduling algorithm is best suited for a given situation. This project aims to address that challenge. The CPU Scheduling Simulator provides an environment where users can experimentally test and compare the performance of different scheduling algorithms through simulation. At the start, users can select any CPU scheduling algorithm they wish to evaluate. They then input the number of processes and relevant details for each process, such as CPU burst time, process ID, priority (if a priority scheduling policy is chosen), arrival time, and more. The simulator visually demonstrates the execution of processes, showing the remaining wait and burst times, as well as the processes waiting in the ready queue. One of the key features of this project is its Graphical User Interface, making it user-friendly and easy to operate. 22 | 23 | ## Features 24 | 25 | - **Multiple Scheduling Algorithms**: Simulates various CPU scheduling algorithms such as FCFS, SJN, RR, and more. 26 | - **User Interface**: Provides a graphical user interface (GUI) for easy interaction and visualization. 27 | - **Detailed Output**: Displays the order of process execution, waiting time, turnaround time, and other performance metrics. 28 | - **Custom Data Structures**: Tailored data structures for managing processes and scheduling tasks. 29 | 30 | 31 | ## Files and Directories 32 | - `sources/`: Directory for additional source files. 33 | - `src/main/`: Main source code directory where the implementation of CPU scheduling algorithms resides. 34 | - `target/`: Directory for compiled classes and build artifacts. 35 | - `pom.xml`: Maven project file for managing dependencies and build configurations. 36 | 37 | ## Getting Started 38 | 39 | ### Prerequisites 40 | 41 | - Java Development Kit (JDK) 8 or higher. 42 | - Apache Maven (optional, for building the project). 43 | - A Java IDE (e.g., IntelliJ IDEA, Eclipse) or any text editor with Java support. 44 | 45 | ### Installation 46 | 47 | 1. Clone the repository to your local machine using: 48 | ```bash 49 | git clone https://github.com/ammarlodhi255/cpu-scheduling-simulator.git 50 | ``` 51 | 52 | 2. Navigate to the project directory: 53 | ```bash 54 | cd cpu-scheduling-simulator 55 | ``` 56 | 57 | 3. Open the project in your preferred Java IDE. 58 | 59 | ### Usage 60 | 61 | 1. **Compile the project**: Ensure all `.java` files are compiled. Most IDEs handle this automatically. 62 | 2. **Run the Simulator**: 63 | - Execute the main class in `src/main/` to launch the simulator's user interface. 64 | - Choose the desired CPU scheduling algorithm and input the process data. 65 | 3. **View Results**: 66 | - The simulator will display the sequence of process execution and calculate important metrics like waiting time, turnaround time, and CPU utilization. 67 | 68 | ### Example 69 | 70 | - **Simulating Round Robin Scheduling**: 71 | 1. Open the simulator. 72 | 2. Select "Round Robin" from the list of algorithms. 73 | 3. Input the number of process. 74 | 4. Click "Start" to see the order of execution and performance metrics. 75 | 76 | ## Contributing 77 | 78 | If you'd like to contribute to this project, please fork the repository and use a feature branch. Pull requests are warmly welcome. 79 | 80 | 1. Fork the repository. 81 | 2. Create a new feature branch. 82 | 3. Commit your changes. 83 | 4. Push to the branch. 84 | 5. Submit a pull request. 85 | 86 | ## YouTube Video 87 | Video link of project demonstration: https://www.youtube.com/watch?v=Rf6Ec8PjOyg 88 | -------------------------------------------------------------------------------- /src/main/java/AbsoluteLayout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | import java.awt.*; 21 | 22 | /** AbsoluteLayout is a LayoutManager that works as a replacement for "null" layout to 23 | * allow placement of components in absolute positions. 24 | * 25 | * @see AbsoluteConstraints 26 | * @version 1.01, Aug 19, 1998 27 | */ 28 | public class AbsoluteLayout implements LayoutManager2, java.io.Serializable { 29 | /** generated Serialized Version UID */ 30 | static final long serialVersionUID = -1919857869177070440L; 31 | 32 | /** Adds the specified component with the specified name to 33 | * the layout. 34 | * @param name the component name 35 | * @param comp the component to be added 36 | */ 37 | public void addLayoutComponent(String name, Component comp) { 38 | throw new IllegalArgumentException(); 39 | } 40 | 41 | /** Removes the specified component from the layout. 42 | * @param comp the component to be removed 43 | */ 44 | public void removeLayoutComponent(Component comp) { 45 | constraints.remove(comp); 46 | } 47 | 48 | /** Calculates the preferred dimension for the specified 49 | * panel given the components in the specified parent container. 50 | * @param parent the component to be laid out 51 | * 52 | * @see #minimumLayoutSize 53 | */ 54 | public Dimension preferredLayoutSize(Container parent) { 55 | int maxWidth = 0; 56 | int maxHeight = 0; 57 | for (java.util.Enumeration e = constraints.keys(); e.hasMoreElements();) { 58 | Component comp = (Component)e.nextElement(); 59 | AbsoluteConstraints ac = (AbsoluteConstraints)constraints.get(comp); 60 | Dimension size = comp.getPreferredSize(); 61 | 62 | int width = ac.getWidth (); 63 | if (width == -1) width = size.width; 64 | int height = ac.getHeight (); 65 | if (height == -1) height = size.height; 66 | 67 | if (ac.x + width > maxWidth) 68 | maxWidth = ac.x + width; 69 | if (ac.y + height > maxHeight) 70 | maxHeight = ac.y + height; 71 | } 72 | return new Dimension (maxWidth, maxHeight); 73 | } 74 | 75 | /** Calculates the minimum dimension for the specified 76 | * panel given the components in the specified parent container. 77 | * @param parent the component to be laid out 78 | * @see #preferredLayoutSize 79 | */ 80 | public Dimension minimumLayoutSize(Container parent) { 81 | int maxWidth = 0; 82 | int maxHeight = 0; 83 | for (java.util.Enumeration e = constraints.keys(); e.hasMoreElements();) { 84 | Component comp = (Component)e.nextElement(); 85 | AbsoluteConstraints ac = (AbsoluteConstraints)constraints.get(comp); 86 | 87 | Dimension size = comp.getMinimumSize(); 88 | 89 | int width = ac.getWidth (); 90 | if (width == -1) width = size.width; 91 | int height = ac.getHeight (); 92 | if (height == -1) height = size.height; 93 | 94 | if (ac.x + width > maxWidth) 95 | maxWidth = ac.x + width; 96 | if (ac.y + height > maxHeight) 97 | maxHeight = ac.y + height; 98 | } 99 | return new Dimension (maxWidth, maxHeight); 100 | } 101 | 102 | /** Lays out the container in the specified panel. 103 | * @param parent the component which needs to be laid out 104 | */ 105 | public void layoutContainer(Container parent) { 106 | for (java.util.Enumeration e = constraints.keys(); e.hasMoreElements();) { 107 | Component comp = (Component)e.nextElement(); 108 | AbsoluteConstraints ac = (AbsoluteConstraints)constraints.get(comp); 109 | Dimension size = comp.getPreferredSize(); 110 | int width = ac.getWidth (); 111 | if (width == -1) width = size.width; 112 | int height = ac.getHeight (); 113 | if (height == -1) height = size.height; 114 | 115 | comp.setBounds(ac.x, ac.y, width, height); 116 | } 117 | } 118 | 119 | /** Adds the specified component to the layout, using the specified 120 | * constraint object. 121 | * @param comp the component to be added 122 | * @param constr where/how the component is added to the layout. 123 | */ 124 | public void addLayoutComponent(Component comp, Object constr) { 125 | if (!(constr instanceof AbsoluteConstraints)) 126 | throw new IllegalArgumentException(); 127 | constraints.put(comp, constr); 128 | } 129 | 130 | /** Returns the maximum size of this component. 131 | * @see java.awt.Component#getMinimumSize() 132 | * @see java.awt.Component#getPreferredSize() 133 | * @see LayoutManager 134 | */ 135 | public Dimension maximumLayoutSize(Container target) { 136 | return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); 137 | } 138 | 139 | /** Returns the alignment along the x axis. This specifies how 140 | * the component would like to be aligned relative to other 141 | * components. The value should be a number between 0 and 1 142 | * where 0 represents alignment along the origin, 1 is aligned 143 | * the furthest away from the origin, 0.5 is centered, etc. 144 | */ 145 | public float getLayoutAlignmentX(Container target) { 146 | return 0; 147 | } 148 | 149 | /** Returns the alignment along the y axis. This specifies how 150 | * the component would like to be aligned relative to other 151 | * components. The value should be a number between 0 and 1 152 | * where 0 represents alignment along the origin, 1 is aligned 153 | * the furthest away from the origin, 0.5 is centered, etc. 154 | */ 155 | public float getLayoutAlignmentY(Container target) { 156 | return 0; 157 | } 158 | 159 | /** Invalidates the layout, indicating that if the layout manager 160 | * has cached information it should be discarded. 161 | */ 162 | public void invalidateLayout(Container target) { 163 | } 164 | 165 | 166 | /** A mapping */ 167 | protected java.util.Hashtable constraints = new java.util.Hashtable(); 168 | } 169 | 170 | -------------------------------------------------------------------------------- /src/main/java/CPUScheduler.java: -------------------------------------------------------------------------------- 1 | 2 | import java.awt.Color; 3 | import java.util.concurrent.TimeUnit; 4 | import javax.swing.*; 5 | 6 | public class CPUScheduler extends Thread { 7 | Job[] jobBatch; 8 | Scheduler policy; 9 | JTextArea textArea; 10 | JTextField textField; 11 | JProgressBar[] pbars; 12 | JLabel[] burstTimes; 13 | ComputationThread[] myThreads = new ComputationThread[SchedulingGUI.NUM_OF_PROCESSES]; 14 | JLabel[] waitingTimes, priorities; 15 | static int statusSum = 0; 16 | 17 | public CPUScheduler(Job[] jobBatch, Scheduler policy, JTextArea textArea, JTextField textField, JProgressBar[] pbars, 18 | JLabel[] burstTimes, JLabel[] waitingTimes, JLabel[] priorities) { 19 | this.jobBatch = jobBatch; 20 | this.policy = policy; 21 | this.textArea = textArea; 22 | this.textField = textField; 23 | this.pbars = pbars; 24 | this.burstTimes = burstTimes; 25 | this.waitingTimes = waitingTimes; 26 | this.priorities = priorities; 27 | } 28 | 29 | public void run() { 30 | if(CalcSimulation.algo.equals("FCFS")) { 31 | Job arrivedJob; 32 | 33 | for(int i = 0; i < jobBatch.length; i++) { 34 | arrivedJob = jobBatch[i]; 35 | policy.enqueue(arrivedJob); 36 | } 37 | 38 | int i = 0; 39 | while(!policy.isEmpty()) { 40 | JProgressBar pbar = pbars[i]; 41 | JLabel burstTime = burstTimes[i]; 42 | long arrivalTime = policy.peek().job.arrivalTime; 43 | //pbar.setBackground(Color.blue); 44 | 45 | try { 46 | Thread.sleep(arrivalTime); 47 | } catch(Exception e) {} 48 | 49 | Job newJob = policy.dequeue(); 50 | int durationInS = (int) TimeUnit.NANOSECONDS.toSeconds(newJob.waitTime); 51 | waitingTimes[i].setText(String.valueOf(durationInS) + "s"); 52 | myThreads[i] = new ComputationThread(newJob, policy, textArea, textField, pbar, burstTime); 53 | myThreads[i].t.start(); 54 | i++; 55 | } 56 | } else if(CalcSimulation.algo.equals("Round Robin")) { 57 | 58 | for(int i = 0; i < jobBatch.length; i++) { 59 | jobBatch[i].progressBar = pbars[i]; 60 | jobBatch[i].burstTimeLabel = burstTimes[i]; 61 | jobBatch[i].waitTimeLabel = waitingTimes[i]; 62 | policy.enqueue(jobBatch[i]); 63 | } 64 | 65 | int i = 0; 66 | while(!policy.isEmpty()) { 67 | long arrivalTime = policy.peek().job.arrivalTime; 68 | try { 69 | Thread.sleep(arrivalTime); 70 | } catch(Exception e) {} 71 | 72 | Job newJob = policy.dequeue(); 73 | int durationInS = (int) TimeUnit.NANOSECONDS.toSeconds(newJob.waitTime); 74 | newJob.waitTimeLabel.setText(String.valueOf(durationInS) + "s"); 75 | myThreads[0] = new ComputationThread(newJob, policy, textArea, textField, 76 | newJob.progressBar, newJob.burstTimeLabel); 77 | myThreads[0].t.start(); 78 | try { 79 | myThreads[0].t.join(); 80 | } catch(Exception ex) {} 81 | } 82 | 83 | for(int j = 1; j < myThreads.length; j++) 84 | myThreads[j] = new ComputationThread(null, null, null, null, null, null); 85 | } 86 | else if (CalcSimulation.algo.equals("Priority Scheduling")) { 87 | 88 | MaxPriorityQueue mp = new MaxPriorityQueue(); 89 | MaxPriorityQueue tempmp = new MaxPriorityQueue(); 90 | 91 | for(int i = 0; i < jobBatch.length; i++) { 92 | int priority = (new java.util.Random().nextInt(10) + 1); 93 | JProgressBar pbar = pbars[i]; 94 | JLabel burstTime = burstTimes[i]; 95 | jobBatch[i].progressBar = pbar; 96 | jobBatch[i].burstTimeLabel = burstTime; 97 | jobBatch[i].priority = priority; 98 | jobBatch[i].waitTimeLabel = waitingTimes[i]; 99 | priorities[i].setText(String.valueOf(jobBatch[i].priority)); 100 | mp.insert(jobBatch[i]); 101 | tempmp.insert(jobBatch[i]); 102 | } 103 | 104 | while(!tempmp.isEmpty()) { 105 | policy.enqueue(tempmp.extractMax()); 106 | } 107 | 108 | while(!mp.isEmpty()) { 109 | long arrivalTime = mp.getMax().arrivalTime; 110 | try { 111 | Thread.sleep(arrivalTime); 112 | } catch(Exception e) {} 113 | 114 | Job newJob = mp.extractMax(); 115 | policy.dequeue(); 116 | newJob.waitTime = System.nanoTime() - newJob.startTime; 117 | int durationInS = (int) TimeUnit.NANOSECONDS.toSeconds(newJob.waitTime); 118 | newJob.waitTimeLabel.setText(String.valueOf(durationInS) + "s"); 119 | ComputationThread cpu = new ComputationThread(newJob, policy, textArea, 120 | textField, newJob.progressBar, newJob.burstTimeLabel); 121 | cpu.t.start(); 122 | 123 | try { 124 | cpu.t.join(); 125 | } catch(InterruptedException ex) {} 126 | } 127 | } else { 128 | MaxPriorityQueue tempmp = new MaxPriorityQueue(); 129 | 130 | for(int i = 0; i < jobBatch.length; i++) { 131 | int priority = (int) jobBatch[i].burstTime; 132 | JProgressBar pbar = pbars[i]; 133 | JLabel burstTime = burstTimes[i]; 134 | jobBatch[i].progressBar = pbar; 135 | jobBatch[i].burstTimeLabel = burstTime; 136 | jobBatch[i].priority = priority; 137 | jobBatch[i].waitTimeLabel = waitingTimes[i]; 138 | priorities[i].setText(String.valueOf(jobBatch[i].priority)); 139 | tempmp.insert(jobBatch[i]); 140 | } 141 | 142 | while(!tempmp.isEmpty()) { 143 | policy.enqueue(tempmp.extractMax()); 144 | } 145 | 146 | while(!policy.isEmpty()) { 147 | long arrivalTime = policy.peek().job.arrivalTime; 148 | try { 149 | Thread.sleep(arrivalTime); 150 | } catch(Exception e) {} 151 | 152 | Job newJob = policy.dequeue(); 153 | newJob.waitTime = System.nanoTime() - newJob.startTime; 154 | int durationInS = (int) TimeUnit.NANOSECONDS.toSeconds(newJob.waitTime); 155 | newJob.waitTimeLabel.setText(String.valueOf(durationInS) + "s"); 156 | ComputationThread cpu = new ComputationThread(newJob, policy, textArea, 157 | textField, newJob.progressBar, newJob.burstTimeLabel); 158 | cpu.t.start(); 159 | 160 | try { 161 | cpu.t.join(); 162 | } catch(InterruptedException ex) {} 163 | } 164 | } 165 | 166 | System.out.println("GOT OUT"); 167 | if(!CalcSimulation.algo.equals("Priority Scheduling") && 168 | !CalcSimulation.algo.equals("Shortest Job First")) { 169 | try { 170 | for(int j = 0; j < myThreads.length; j++) 171 | myThreads[j].t.join(); 172 | } catch(InterruptedException ex) {} 173 | } 174 | 175 | textField.setText("Idle"); 176 | textField.setForeground(Color.red); 177 | 178 | long avgWaitTime = 0; 179 | long avgTurnaroundTime = 0; 180 | long totalExecutionTime = 0; 181 | 182 | for(int j = 0; j < jobBatch.length; j++) { 183 | avgWaitTime += jobBatch[j].waitTime; 184 | avgTurnaroundTime += jobBatch[j].endTime; 185 | } 186 | 187 | avgWaitTime /= jobBatch.length; 188 | avgWaitTime = TimeUnit.NANOSECONDS.toSeconds(avgWaitTime); 189 | CalcSimulation.avgWaitField.setText(String.valueOf(avgWaitTime) + "s"); 190 | 191 | avgTurnaroundTime = TimeUnit.NANOSECONDS.toSeconds(avgTurnaroundTime/jobBatch.length); 192 | CalcSimulation.avgServeField.setText(String.valueOf(avgTurnaroundTime) + "s"); 193 | 194 | totalExecutionTime = System.nanoTime() - CalcSimulation.STRTTIME; 195 | totalExecutionTime = TimeUnit.NANOSECONDS.toSeconds(totalExecutionTime); 196 | CalcSimulation.totalExecField.setText(String.valueOf(totalExecutionTime) + "s"); 197 | } 198 | 199 | } 200 | -------------------------------------------------------------------------------- /src/main/java/SchedulingGUI.java: -------------------------------------------------------------------------------- 1 | import java.awt.event.WindowAdapter; 2 | import java.awt.event.WindowEvent; 3 | import javax.swing.*; 4 | import java.io.File; 5 | import java.util.Random; 6 | 7 | public class SchedulingGUI extends JFrame { 8 | private String[] algorithms = {"FCFS", "Round Robin", "Shortest Job First", "Priority Scheduling"}; 9 | private String sourcePath = new String(); 10 | public static int NUM_OF_PROCESSES = 0; 11 | static String selectedAlgo = new String(); 12 | 13 | public SchedulingGUI() { 14 | initComponents(); 15 | jLabel7.setIcon(new javax.swing.ImageIcon("src\\main\\java\\dark-abstract-tech-background_53876-90630.jpg")); 16 | setResizable(false); 17 | setTitle("CPU Scheduling Simulator"); 18 | jComboBox1.setModel(new DefaultComboBoxModel<>(algorithms)); 19 | addWindowListener(new WindowListener()); 20 | setLocationRelativeTo(null); 21 | } 22 | 23 | private class WindowListener extends WindowAdapter { 24 | public void windowOpened(WindowEvent e) { 25 | TitleThread thread = new TitleThread("Simulation", jLabel1, 200); 26 | thread.start(); 27 | } 28 | } 29 | 30 | @SuppressWarnings("unchecked") 31 | // //GEN-BEGIN:initComponents 32 | private void initComponents() { 33 | 34 | jPanel1 = new javax.swing.JPanel(); 35 | jLabel2 = new javax.swing.JLabel(); 36 | jComboBox1 = new javax.swing.JComboBox<>(); 37 | jLabel3 = new javax.swing.JLabel(); 38 | jButton1 = new javax.swing.JButton(); 39 | jButton2 = new javax.swing.JButton(); 40 | jLabel4 = new javax.swing.JLabel(); 41 | jLabel1 = new javax.swing.JLabel(); 42 | jLabel5 = new javax.swing.JLabel(); 43 | jTextField1 = new javax.swing.JTextField(); 44 | nextStep2 = new javax.swing.JButton(); 45 | jLabel6 = new javax.swing.JLabel(); 46 | jLabel7 = new javax.swing.JLabel(); 47 | 48 | setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 49 | 50 | jPanel1.setBackground(new java.awt.Color(0, 102, 102)); 51 | jPanel1.setLayout(new AbsoluteLayout()); 52 | 53 | jLabel2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N 54 | jLabel2.setForeground(new java.awt.Color(255, 255, 255)); 55 | jLabel2.setText("# of Process:"); 56 | jPanel1.add(jLabel2, new AbsoluteConstraints(320, 290, 130, 30)); 57 | 58 | jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); 59 | jPanel1.add(jComboBox1, new AbsoluteConstraints(490, 190, 140, 30)); 60 | 61 | jLabel3.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N 62 | jLabel3.setForeground(new java.awt.Color(255, 255, 255)); 63 | jLabel3.setText("Algorithm:"); 64 | jPanel1.add(jLabel3, new AbsoluteConstraints(320, 190, 100, 30)); 65 | 66 | jButton1.setText("Browse"); 67 | jButton1.addActionListener(new java.awt.event.ActionListener() { 68 | public void actionPerformed(java.awt.event.ActionEvent evt) { 69 | jButton1ActionPerformed(evt); 70 | } 71 | }); 72 | jPanel1.add(jButton1, new AbsoluteConstraints(490, 240, 140, 30)); 73 | 74 | jButton2.setFont(new java.awt.Font("Tahoma", 3, 12)); // NOI18N 75 | jButton2.setText("Team Info"); 76 | jButton2.addActionListener(new java.awt.event.ActionListener() { 77 | public void actionPerformed(java.awt.event.ActionEvent evt) { 78 | jButton2ActionPerformed(evt); 79 | } 80 | }); 81 | jPanel1.add(jButton2, new AbsoluteConstraints(0, 500, 100, 30)); 82 | 83 | jLabel4.setFont(new java.awt.Font("Bookman Old Style", 1, 48)); // NOI18N 84 | jLabel4.setForeground(new java.awt.Color(255, 255, 255)); 85 | jLabel4.setText("CPU Scheduling"); 86 | jPanel1.add(jLabel4, new AbsoluteConstraints(280, 10, 420, 80)); 87 | 88 | jLabel1.setFont(new java.awt.Font("Bookman Old Style", 3, 18)); // NOI18N 89 | jLabel1.setForeground(new java.awt.Color(255, 255, 255)); 90 | jLabel1.setText("Simulation"); 91 | jPanel1.add(jLabel1, new AbsoluteConstraints(410, 90, 120, -1)); 92 | 93 | jLabel5.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N 94 | jLabel5.setForeground(new java.awt.Color(255, 255, 255)); 95 | jLabel5.setText("Source:"); 96 | jPanel1.add(jLabel5, new AbsoluteConstraints(320, 240, 70, 30)); 97 | 98 | jTextField1.setText("0"); 99 | jPanel1.add(jTextField1, new AbsoluteConstraints(490, 290, 140, 30)); 100 | 101 | nextStep2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N 102 | nextStep2.setText("Start"); 103 | nextStep2.addActionListener(new java.awt.event.ActionListener() { 104 | public void actionPerformed(java.awt.event.ActionEvent evt) { 105 | nextStep2ActionPerformed(evt); 106 | } 107 | }); 108 | jPanel1.add(nextStep2, new AbsoluteConstraints(410, 370, 130, 40)); 109 | 110 | jLabel6.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N 111 | jLabel6.setForeground(new java.awt.Color(255, 255, 255)); 112 | jLabel6.setText("(0 <= N <= 10)"); 113 | jPanel1.add(jLabel6, new AbsoluteConstraints(650, 290, 120, 30)); 114 | 115 | jLabel7.setIcon(new javax.swing.ImageIcon("D:\\Programming Files\\CPUSchedulingSimulation\\src\\main\\java\\dark-abstract-tech-background_53876-90630.jpg")); // NOI18N 116 | jPanel1.add(jLabel7, new AbsoluteConstraints(0, 0, 960, 530)); 117 | 118 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 119 | getContentPane().setLayout(layout); 120 | layout.setHorizontalGroup( 121 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 122 | .addGroup(layout.createSequentialGroup() 123 | .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 957, javax.swing.GroupLayout.PREFERRED_SIZE) 124 | .addGap(0, 0, Short.MAX_VALUE)) 125 | ); 126 | layout.setVerticalGroup( 127 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 128 | .addGroup(layout.createSequentialGroup() 129 | .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 533, javax.swing.GroupLayout.PREFERRED_SIZE) 130 | .addGap(0, 0, Short.MAX_VALUE)) 131 | ); 132 | 133 | jPanel1.getAccessibleContext().setAccessibleName(""); 134 | 135 | pack(); 136 | setLocationRelativeTo(null); 137 | }// //GEN-END:initComponents 138 | 139 | private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed 140 | JFileChooser fileChooser = new JFileChooser(); 141 | fileChooser.showOpenDialog(null); 142 | File file = fileChooser.getSelectedFile(); 143 | sourcePath = file.getAbsolutePath(); 144 | }//GEN-LAST:event_jButton1ActionPerformed 145 | 146 | private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed 147 | JOptionPane.showMessageDialog(null, "Developers:\n\nAmmar Ahmed, BSCS-IV.\nSuraksha Sadhwani, BSCS-IV."); 148 | }//GEN-LAST:event_jButton2ActionPerformed 149 | 150 | private void nextStep2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextStep2ActionPerformed 151 | int numOfProcesses = Integer.parseInt(jTextField1.getText()); 152 | if(sourcePath.isEmpty()) 153 | JOptionPane.showMessageDialog(null, "ERROR: Please input the source of computation"); 154 | else if(numOfProcesses <= 0) 155 | JOptionPane.showMessageDialog(null, "ERROR: Please input the appropriate number of processes"); 156 | else { 157 | selectedAlgo = jComboBox1.getSelectedItem().toString(); 158 | NUM_OF_PROCESSES = Integer.parseInt(jTextField1.getText()); 159 | Job[] jobs = new Job[NUM_OF_PROCESSES]; 160 | for(int i = 1; i <= NUM_OF_PROCESSES; i++) { 161 | String processID = "P"+i; 162 | long arrivalTime = (new java.util.Random().nextInt(9) + 1) * 300; 163 | long burstTime = (new java.util.Random().nextInt(3) + 1) * 100; 164 | long STRTTIME = System.nanoTime(); 165 | 166 | Job newJob = new Job(processID, arrivalTime, burstTime, STRTTIME); 167 | jobs[(i-1)] = newJob; 168 | } 169 | CalcSimulation sim = 170 | new CalcSimulation(jobs, NUM_OF_PROCESSES, sourcePath, selectedAlgo); 171 | sim.start(); 172 | this.dispose(); 173 | } 174 | }//GEN-LAST:event_nextStep2ActionPerformed 175 | 176 | 177 | public static void main(String args[]) { 178 | try { 179 | for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { 180 | if ("Nimbus".equals(info.getName())) { 181 | javax.swing.UIManager.setLookAndFeel(info.getClassName()); 182 | break; 183 | } 184 | } 185 | } catch (ClassNotFoundException ex) { 186 | java.util.logging.Logger.getLogger(SchedulingGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 187 | } catch (InstantiationException ex) { 188 | java.util.logging.Logger.getLogger(SchedulingGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 189 | } catch (IllegalAccessException ex) { 190 | java.util.logging.Logger.getLogger(SchedulingGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 191 | } catch (javax.swing.UnsupportedLookAndFeelException ex) { 192 | java.util.logging.Logger.getLogger(SchedulingGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 193 | } 194 | java.awt.EventQueue.invokeLater(new Runnable() { 195 | public void run() { 196 | new SchedulingGUI().setVisible(true); 197 | } 198 | }); 199 | } 200 | 201 | // Variables declaration - do not modify//GEN-BEGIN:variables 202 | private javax.swing.JButton jButton1; 203 | private javax.swing.JButton jButton2; 204 | private javax.swing.JComboBox jComboBox1; 205 | private javax.swing.JLabel jLabel1; 206 | private javax.swing.JLabel jLabel2; 207 | private javax.swing.JLabel jLabel3; 208 | private javax.swing.JLabel jLabel4; 209 | private javax.swing.JLabel jLabel5; 210 | private javax.swing.JLabel jLabel6; 211 | private javax.swing.JLabel jLabel7; 212 | private javax.swing.JPanel jPanel1; 213 | private javax.swing.JTextField jTextField1; 214 | private javax.swing.JButton nextStep2; 215 | // End of variables declaration//GEN-END:variables 216 | } 217 | -------------------------------------------------------------------------------- /src/main/java/SchedulingGUI.form: -------------------------------------------------------------------------------- 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 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | -------------------------------------------------------------------------------- /src/main/java/CalcSimulation.java: -------------------------------------------------------------------------------- 1 | import java.awt.Color; 2 | import java.io.File; 3 | import javax.swing.*; 4 | 5 | public class CalcSimulation extends javax.swing.JFrame { 6 | Job[] jobBatch; 7 | int numOfJobs; 8 | public FCFSPolicy fifo; 9 | String sourcePath; 10 | static String algo; 11 | JProgressBar[] pbars = new JProgressBar[10]; 12 | JLabel[] burstTimes = new JLabel[10], waitingTimes = new JLabel[10]; 13 | JLabel[] priorities = new JLabel[10]; 14 | static long STRTTIME; 15 | 16 | public CalcSimulation(Job[] jobBatch, int numOfJobs, String sourcePath, String algo) { 17 | this.jobBatch = jobBatch; 18 | this.numOfJobs = numOfJobs; 19 | this.sourcePath = sourcePath; 20 | this.algo = algo; 21 | initComponents(); 22 | jLabel1.setIcon(new javax.swing.ImageIcon("src\\main\\java\\dark-abstract2.jpg")); 23 | selectedAlgo.setText(algo); 24 | setVisible(true); 25 | setResizable(false); 26 | setLocationRelativeTo(null); 27 | 28 | pbars[0] = jProgressBar1; 29 | pbars[1] = jProgressBar2; 30 | pbars[2] = jProgressBar3; 31 | pbars[3] = jProgressBar4; 32 | pbars[4] = jProgressBar5; 33 | pbars[5] = jProgressBar6; 34 | pbars[6] = jProgressBar7; 35 | pbars[7] = jProgressBar8; 36 | pbars[8] = jProgressBar9; 37 | pbars[9] = jProgressBar10; 38 | 39 | burstTimes[0] = bst1; 40 | burstTimes[1] = bst2; 41 | burstTimes[2] = bst3; 42 | burstTimes[3] = bst4; 43 | burstTimes[4] = bst5; 44 | burstTimes[5] = bst6; 45 | burstTimes[6] = bst7; 46 | burstTimes[7] = bst8; 47 | burstTimes[8] = bst9; 48 | burstTimes[9] = bst10; 49 | 50 | waitingTimes[0] = bst11; 51 | waitingTimes[1] = bst12; 52 | waitingTimes[2] = bst13; 53 | waitingTimes[3] = bst14; 54 | waitingTimes[4] = bst15; 55 | waitingTimes[5] = bst16; 56 | waitingTimes[6] = bst17; 57 | waitingTimes[7] = bst18; 58 | waitingTimes[8] = bst19; 59 | waitingTimes[9] = bst20; 60 | 61 | priorities[0] = pt1; 62 | priorities[1] = pt2; 63 | priorities[2] = pt3; 64 | priorities[3] = pt4; 65 | priorities[4] = pt5; 66 | priorities[5] = pt6; 67 | priorities[6] = pt7; 68 | priorities[7] = pt8; 69 | priorities[8] = pt9; 70 | priorities[9] = pt10; 71 | 72 | STRTTIME = System.nanoTime(); 73 | } 74 | 75 | public void start() { 76 | if(algo.equals("FCFS")) { 77 | fifo = new FCFSPolicy(new File(sourcePath)); 78 | CPUScheduler scheduler = new CPUScheduler(jobBatch, fifo, jTextArea1, selectedJob, 79 | pbars, burstTimes, waitingTimes, priorities); 80 | scheduler.start(); 81 | } else if (algo.equals("Round Robin")) { 82 | RoundRobinPolicy rr = new RoundRobinPolicy(new File(sourcePath)); 83 | CPUScheduler scheduler = new CPUScheduler(jobBatch, rr, jTextArea1, selectedJob, 84 | pbars, burstTimes, waitingTimes, priorities); 85 | scheduler.start(); 86 | } else if(algo.equals("Priority Scheduling")) { 87 | 88 | jLabel14.setText("Priority"); 89 | 90 | PriorityPolicy pp = new PriorityPolicy(new File(sourcePath)); 91 | CPUScheduler scheduler = new CPUScheduler(jobBatch, pp, jTextArea1, selectedJob, 92 | pbars, burstTimes, waitingTimes, priorities); 93 | scheduler.start(); 94 | } else { 95 | jLabel14.setText("Burst"); 96 | Stack stack = new Stack(new File(sourcePath)); 97 | CPUScheduler scheduler = new CPUScheduler(jobBatch, stack, jTextArea1, selectedJob, 98 | pbars, burstTimes, waitingTimes, priorities); 99 | scheduler.start(); 100 | } 101 | } 102 | @SuppressWarnings("unchecked") 103 | // //GEN-BEGIN:initComponents 104 | private void initComponents() { 105 | 106 | jPanel1 = new javax.swing.JPanel(); 107 | jScrollPane1 = new javax.swing.JScrollPane(); 108 | jTextArea1 = new javax.swing.JTextArea(); 109 | jProgressBar1 = new javax.swing.JProgressBar(); 110 | jLabel2 = new javax.swing.JLabel(); 111 | jLabel3 = new javax.swing.JLabel(); 112 | algoSelected2 = new javax.swing.JLabel(); 113 | selectedAlgo = new javax.swing.JTextField(); 114 | pt1 = new javax.swing.JLabel(); 115 | jProgressBar2 = new javax.swing.JProgressBar(); 116 | jLabel4 = new javax.swing.JLabel(); 117 | jProgressBar3 = new javax.swing.JProgressBar(); 118 | jLabel5 = new javax.swing.JLabel(); 119 | jProgressBar4 = new javax.swing.JProgressBar(); 120 | jLabel6 = new javax.swing.JLabel(); 121 | jProgressBar5 = new javax.swing.JProgressBar(); 122 | jLabel7 = new javax.swing.JLabel(); 123 | jProgressBar6 = new javax.swing.JProgressBar(); 124 | jLabel8 = new javax.swing.JLabel(); 125 | jProgressBar7 = new javax.swing.JProgressBar(); 126 | jLabel9 = new javax.swing.JLabel(); 127 | jProgressBar8 = new javax.swing.JProgressBar(); 128 | jLabel10 = new javax.swing.JLabel(); 129 | jProgressBar9 = new javax.swing.JProgressBar(); 130 | jLabel11 = new javax.swing.JLabel(); 131 | jProgressBar10 = new javax.swing.JProgressBar(); 132 | jLabel12 = new javax.swing.JLabel(); 133 | jLabel13 = new javax.swing.JLabel(); 134 | jLabel14 = new javax.swing.JLabel(); 135 | jLabel15 = new javax.swing.JLabel(); 136 | bst3 = new javax.swing.JLabel(); 137 | bst1 = new javax.swing.JLabel(); 138 | bst2 = new javax.swing.JLabel(); 139 | bst6 = new javax.swing.JLabel(); 140 | bst5 = new javax.swing.JLabel(); 141 | bst4 = new javax.swing.JLabel(); 142 | bst10 = new javax.swing.JLabel(); 143 | bst8 = new javax.swing.JLabel(); 144 | bst7 = new javax.swing.JLabel(); 145 | bst9 = new javax.swing.JLabel(); 146 | bst11 = new javax.swing.JLabel(); 147 | bst12 = new javax.swing.JLabel(); 148 | bst13 = new javax.swing.JLabel(); 149 | bst14 = new javax.swing.JLabel(); 150 | bst15 = new javax.swing.JLabel(); 151 | bst16 = new javax.swing.JLabel(); 152 | bst17 = new javax.swing.JLabel(); 153 | bst18 = new javax.swing.JLabel(); 154 | bst19 = new javax.swing.JLabel(); 155 | bst20 = new javax.swing.JLabel(); 156 | jLabel17 = new javax.swing.JLabel(); 157 | avgServeLabel = new javax.swing.JLabel(); 158 | selectedJob = new javax.swing.JTextField(); 159 | avgWaitField = new javax.swing.JTextField(); 160 | avgServeField = new javax.swing.JTextField(); 161 | totalExecField = new javax.swing.JTextField(); 162 | avgTurnLabel1 = new javax.swing.JLabel(); 163 | jLabel16 = new javax.swing.JLabel(); 164 | pt2 = new javax.swing.JLabel(); 165 | pt3 = new javax.swing.JLabel(); 166 | pt4 = new javax.swing.JLabel(); 167 | jLabel18 = new javax.swing.JLabel(); 168 | pt5 = new javax.swing.JLabel(); 169 | pt6 = new javax.swing.JLabel(); 170 | pt7 = new javax.swing.JLabel(); 171 | pt8 = new javax.swing.JLabel(); 172 | pt9 = new javax.swing.JLabel(); 173 | pt10 = new javax.swing.JLabel(); 174 | jLabel1 = new javax.swing.JLabel(); 175 | 176 | setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 177 | 178 | jPanel1.setBackground(new java.awt.Color(0, 102, 102)); 179 | jPanel1.setLayout(new AbsoluteLayout()); 180 | 181 | jTextArea1.setBackground(new java.awt.Color(102, 102, 102)); 182 | jTextArea1.setColumns(20); 183 | jTextArea1.setFont(new java.awt.Font("Tahoma", 3, 18)); // NOI18N 184 | jTextArea1.setForeground(new java.awt.Color(255, 255, 255)); 185 | jTextArea1.setRows(5); 186 | jScrollPane1.setViewportView(jTextArea1); 187 | 188 | jPanel1.add(jScrollPane1, new AbsoluteConstraints(0, 570, 330, 50)); 189 | 190 | jProgressBar1.setBackground(new java.awt.Color(0, 153, 255)); 191 | jPanel1.add(jProgressBar1, new AbsoluteConstraints(580, 70, 270, 30)); 192 | 193 | jLabel2.setFont(new java.awt.Font("Tahoma", 3, 14)); // NOI18N 194 | jLabel2.setForeground(new java.awt.Color(255, 255, 255)); 195 | jLabel2.setText("Ready Queue"); 196 | jPanel1.add(jLabel2, new AbsoluteConstraints(110, 550, 120, 20)); 197 | 198 | jLabel3.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N 199 | jLabel3.setForeground(new java.awt.Color(255, 255, 255)); 200 | jLabel3.setText("Algorithm: "); 201 | jPanel1.add(jLabel3, new AbsoluteConstraints(10, 10, 110, 30)); 202 | 203 | algoSelected2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N 204 | algoSelected2.setForeground(new java.awt.Color(255, 255, 255)); 205 | algoSelected2.setText("CPU:"); 206 | jPanel1.add(algoSelected2, new AbsoluteConstraints(10, 50, 70, 30)); 207 | 208 | selectedAlgo.setBackground(new java.awt.Color(102, 102, 102)); 209 | selectedAlgo.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N 210 | selectedAlgo.setForeground(new java.awt.Color(255, 255, 255)); 211 | selectedAlgo.setText("jTextField1"); 212 | jPanel1.add(selectedAlgo, new AbsoluteConstraints(120, 10, 250, 30)); 213 | 214 | pt1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N 215 | pt1.setForeground(new java.awt.Color(255, 255, 255)); 216 | pt1.setText("0"); 217 | jPanel1.add(pt1, new AbsoluteConstraints(470, 70, 30, 30)); 218 | jPanel1.add(jProgressBar2, new AbsoluteConstraints(580, 120, 270, 30)); 219 | 220 | jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N 221 | jLabel4.setForeground(new java.awt.Color(255, 255, 255)); 222 | jLabel4.setText("P2:"); 223 | jPanel1.add(jLabel4, new AbsoluteConstraints(530, 120, 30, 30)); 224 | jPanel1.add(jProgressBar3, new AbsoluteConstraints(580, 170, 270, 30)); 225 | 226 | jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N 227 | jLabel5.setForeground(new java.awt.Color(255, 255, 255)); 228 | jLabel5.setText("P3:"); 229 | jPanel1.add(jLabel5, new AbsoluteConstraints(530, 170, 30, 30)); 230 | jPanel1.add(jProgressBar4, new AbsoluteConstraints(580, 220, 270, 30)); 231 | 232 | jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N 233 | jLabel6.setForeground(new java.awt.Color(255, 255, 255)); 234 | jLabel6.setText("P4:"); 235 | jPanel1.add(jLabel6, new AbsoluteConstraints(530, 220, 30, 30)); 236 | jPanel1.add(jProgressBar5, new AbsoluteConstraints(580, 270, 270, 30)); 237 | 238 | jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N 239 | jLabel7.setForeground(new java.awt.Color(255, 255, 255)); 240 | jLabel7.setText("P5:"); 241 | jPanel1.add(jLabel7, new AbsoluteConstraints(530, 270, 30, 30)); 242 | jPanel1.add(jProgressBar6, new AbsoluteConstraints(580, 320, 270, 30)); 243 | 244 | jLabel8.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N 245 | jLabel8.setForeground(new java.awt.Color(255, 255, 255)); 246 | jLabel8.setText("P6:"); 247 | jPanel1.add(jLabel8, new AbsoluteConstraints(530, 320, 30, 30)); 248 | jPanel1.add(jProgressBar7, new AbsoluteConstraints(580, 370, 270, 30)); 249 | 250 | jLabel9.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N 251 | jLabel9.setForeground(new java.awt.Color(255, 255, 255)); 252 | jLabel9.setText("P7:"); 253 | jPanel1.add(jLabel9, new AbsoluteConstraints(530, 370, 30, 30)); 254 | jPanel1.add(jProgressBar8, new AbsoluteConstraints(580, 420, 270, 30)); 255 | 256 | jLabel10.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N 257 | jLabel10.setForeground(new java.awt.Color(255, 255, 255)); 258 | jLabel10.setText("P8:"); 259 | jPanel1.add(jLabel10, new AbsoluteConstraints(530, 420, 30, 30)); 260 | jPanel1.add(jProgressBar9, new AbsoluteConstraints(580, 470, 270, 30)); 261 | 262 | jLabel11.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N 263 | jLabel11.setForeground(new java.awt.Color(255, 255, 255)); 264 | jLabel11.setText("P9:"); 265 | jPanel1.add(jLabel11, new AbsoluteConstraints(530, 470, 30, 30)); 266 | jPanel1.add(jProgressBar10, new AbsoluteConstraints(580, 520, 270, 30)); 267 | 268 | jLabel12.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N 269 | jLabel12.setForeground(new java.awt.Color(255, 255, 255)); 270 | jLabel12.setText("P10:"); 271 | jPanel1.add(jLabel12, new AbsoluteConstraints(530, 520, 30, 30)); 272 | 273 | jLabel13.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N 274 | jLabel13.setForeground(new java.awt.Color(255, 255, 255)); 275 | jLabel13.setText("Waiting Time"); 276 | jPanel1.add(jLabel13, new AbsoluteConstraints(1110, 20, 120, 30)); 277 | 278 | jLabel14.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N 279 | jLabel14.setForeground(new java.awt.Color(255, 255, 255)); 280 | jLabel14.setText("Priority"); 281 | jPanel1.add(jLabel14, new AbsoluteConstraints(450, 20, 70, 30)); 282 | 283 | jLabel15.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N 284 | jLabel15.setForeground(new java.awt.Color(255, 255, 255)); 285 | jLabel15.setText("Remaining Burst Time"); 286 | jPanel1.add(jLabel15, new AbsoluteConstraints(890, 20, 210, 30)); 287 | 288 | bst3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N 289 | bst3.setForeground(new java.awt.Color(255, 255, 255)); 290 | bst3.setText("0"); 291 | jPanel1.add(bst3, new AbsoluteConstraints(990, 170, 80, 20)); 292 | 293 | bst1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N 294 | bst1.setForeground(new java.awt.Color(255, 255, 255)); 295 | bst1.setText("0"); 296 | jPanel1.add(bst1, new AbsoluteConstraints(990, 70, 80, 20)); 297 | 298 | bst2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N 299 | bst2.setForeground(new java.awt.Color(255, 255, 255)); 300 | bst2.setText("0"); 301 | jPanel1.add(bst2, new AbsoluteConstraints(990, 120, 80, 20)); 302 | 303 | bst6.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N 304 | bst6.setForeground(new java.awt.Color(255, 255, 255)); 305 | bst6.setText("0"); 306 | jPanel1.add(bst6, new AbsoluteConstraints(990, 320, 80, 20)); 307 | 308 | bst5.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N 309 | bst5.setForeground(new java.awt.Color(255, 255, 255)); 310 | bst5.setText("0"); 311 | jPanel1.add(bst5, new AbsoluteConstraints(990, 270, 80, 20)); 312 | 313 | bst4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N 314 | bst4.setForeground(new java.awt.Color(255, 255, 255)); 315 | bst4.setText("0"); 316 | jPanel1.add(bst4, new AbsoluteConstraints(990, 220, 80, 20)); 317 | 318 | bst10.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N 319 | bst10.setForeground(new java.awt.Color(255, 255, 255)); 320 | bst10.setText("0"); 321 | jPanel1.add(bst10, new AbsoluteConstraints(990, 520, 80, 20)); 322 | 323 | bst8.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N 324 | bst8.setForeground(new java.awt.Color(255, 255, 255)); 325 | bst8.setText("0"); 326 | jPanel1.add(bst8, new AbsoluteConstraints(990, 420, 80, 20)); 327 | 328 | bst7.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N 329 | bst7.setForeground(new java.awt.Color(255, 255, 255)); 330 | bst7.setText("0"); 331 | jPanel1.add(bst7, new AbsoluteConstraints(990, 370, 80, 20)); 332 | 333 | bst9.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N 334 | bst9.setForeground(new java.awt.Color(255, 255, 255)); 335 | bst9.setText("0"); 336 | jPanel1.add(bst9, new AbsoluteConstraints(990, 470, 80, 20)); 337 | 338 | bst11.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N 339 | bst11.setForeground(new java.awt.Color(255, 255, 255)); 340 | bst11.setText("0"); 341 | jPanel1.add(bst11, new AbsoluteConstraints(1150, 70, 80, 20)); 342 | 343 | bst12.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N 344 | bst12.setForeground(new java.awt.Color(255, 255, 255)); 345 | bst12.setText("0"); 346 | jPanel1.add(bst12, new AbsoluteConstraints(1150, 120, 80, 20)); 347 | 348 | bst13.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N 349 | bst13.setForeground(new java.awt.Color(255, 255, 255)); 350 | bst13.setText("0"); 351 | jPanel1.add(bst13, new AbsoluteConstraints(1150, 170, 80, 20)); 352 | 353 | bst14.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N 354 | bst14.setForeground(new java.awt.Color(255, 255, 255)); 355 | bst14.setText("0"); 356 | jPanel1.add(bst14, new AbsoluteConstraints(1150, 220, 80, 20)); 357 | 358 | bst15.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N 359 | bst15.setForeground(new java.awt.Color(255, 255, 255)); 360 | bst15.setText("0"); 361 | jPanel1.add(bst15, new AbsoluteConstraints(1150, 270, 80, 20)); 362 | 363 | bst16.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N 364 | bst16.setForeground(new java.awt.Color(255, 255, 255)); 365 | bst16.setText("0"); 366 | jPanel1.add(bst16, new AbsoluteConstraints(1150, 320, 80, 20)); 367 | 368 | bst17.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N 369 | bst17.setForeground(new java.awt.Color(255, 255, 255)); 370 | bst17.setText("0"); 371 | jPanel1.add(bst17, new AbsoluteConstraints(1150, 370, 80, 20)); 372 | 373 | bst18.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N 374 | bst18.setForeground(new java.awt.Color(255, 255, 255)); 375 | bst18.setText("0"); 376 | jPanel1.add(bst18, new AbsoluteConstraints(1150, 420, 80, 20)); 377 | 378 | bst19.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N 379 | bst19.setForeground(new java.awt.Color(255, 255, 255)); 380 | bst19.setText("0"); 381 | jPanel1.add(bst19, new AbsoluteConstraints(1150, 470, 80, 20)); 382 | 383 | bst20.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N 384 | bst20.setForeground(new java.awt.Color(255, 255, 255)); 385 | bst20.setText("0"); 386 | jPanel1.add(bst20, new AbsoluteConstraints(1150, 520, 80, 20)); 387 | 388 | jLabel17.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N 389 | jLabel17.setForeground(new java.awt.Color(255, 255, 255)); 390 | jLabel17.setText("Average Waiting Time:"); 391 | jPanel1.add(jLabel17, new AbsoluteConstraints(10, 200, 220, 50)); 392 | 393 | avgServeLabel.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N 394 | avgServeLabel.setForeground(new java.awt.Color(255, 255, 255)); 395 | avgServeLabel.setText("Average Turnaround Time:"); 396 | jPanel1.add(avgServeLabel, new AbsoluteConstraints(10, 260, 250, 50)); 397 | 398 | selectedJob.setBackground(new java.awt.Color(102, 102, 102)); 399 | selectedJob.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N 400 | selectedJob.setForeground(new java.awt.Color(255, 255, 255)); 401 | selectedJob.setText("P1"); 402 | jPanel1.add(selectedJob, new AbsoluteConstraints(120, 50, 110, 30)); 403 | 404 | avgWaitField.setBackground(new java.awt.Color(102, 102, 102)); 405 | avgWaitField.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N 406 | avgWaitField.setForeground(new java.awt.Color(255, 255, 255)); 407 | jPanel1.add(avgWaitField, new AbsoluteConstraints(280, 210, 80, 30)); 408 | 409 | avgServeField.setBackground(new java.awt.Color(102, 102, 102)); 410 | avgServeField.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N 411 | avgServeField.setForeground(new java.awt.Color(255, 255, 255)); 412 | jPanel1.add(avgServeField, new AbsoluteConstraints(280, 270, 80, 30)); 413 | 414 | totalExecField.setBackground(new java.awt.Color(102, 102, 102)); 415 | totalExecField.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N 416 | totalExecField.setForeground(new java.awt.Color(255, 255, 255)); 417 | jPanel1.add(totalExecField, new AbsoluteConstraints(280, 330, 80, 30)); 418 | 419 | avgTurnLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N 420 | avgTurnLabel1.setForeground(new java.awt.Color(255, 255, 255)); 421 | avgTurnLabel1.setText("Total Execution Time:"); 422 | jPanel1.add(avgTurnLabel1, new AbsoluteConstraints(10, 320, 250, 50)); 423 | 424 | jLabel16.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N 425 | jLabel16.setForeground(new java.awt.Color(255, 255, 255)); 426 | jLabel16.setText("P1:"); 427 | jPanel1.add(jLabel16, new AbsoluteConstraints(530, 70, 30, 30)); 428 | 429 | pt2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N 430 | pt2.setForeground(new java.awt.Color(255, 255, 255)); 431 | pt2.setText("0"); 432 | jPanel1.add(pt2, new AbsoluteConstraints(470, 120, 30, 30)); 433 | 434 | pt3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N 435 | pt3.setForeground(new java.awt.Color(255, 255, 255)); 436 | pt3.setText("0"); 437 | jPanel1.add(pt3, new AbsoluteConstraints(470, 170, 30, 30)); 438 | 439 | pt4.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N 440 | pt4.setForeground(new java.awt.Color(255, 255, 255)); 441 | pt4.setText("0"); 442 | jPanel1.add(pt4, new AbsoluteConstraints(470, 220, 30, 30)); 443 | 444 | jLabel18.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N 445 | jLabel18.setForeground(new java.awt.Color(255, 255, 255)); 446 | jLabel18.setText("Status Bar"); 447 | jPanel1.add(jLabel18, new AbsoluteConstraints(660, 20, 100, 30)); 448 | 449 | pt5.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N 450 | pt5.setForeground(new java.awt.Color(255, 255, 255)); 451 | pt5.setText("0"); 452 | jPanel1.add(pt5, new AbsoluteConstraints(470, 270, 30, 30)); 453 | 454 | pt6.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N 455 | pt6.setForeground(new java.awt.Color(255, 255, 255)); 456 | pt6.setText("0"); 457 | jPanel1.add(pt6, new AbsoluteConstraints(470, 320, 30, 30)); 458 | 459 | pt7.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N 460 | pt7.setForeground(new java.awt.Color(255, 255, 255)); 461 | pt7.setText("0"); 462 | jPanel1.add(pt7, new AbsoluteConstraints(470, 370, 30, 30)); 463 | 464 | pt8.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N 465 | pt8.setForeground(new java.awt.Color(255, 255, 255)); 466 | pt8.setText("0"); 467 | jPanel1.add(pt8, new AbsoluteConstraints(470, 420, 30, 30)); 468 | 469 | pt9.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N 470 | pt9.setForeground(new java.awt.Color(255, 255, 255)); 471 | pt9.setText("0"); 472 | jPanel1.add(pt9, new AbsoluteConstraints(470, 470, 30, 30)); 473 | 474 | pt10.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N 475 | pt10.setForeground(new java.awt.Color(255, 255, 255)); 476 | pt10.setText("0"); 477 | jPanel1.add(pt10, new AbsoluteConstraints(470, 520, 30, 30)); 478 | 479 | jLabel1.setIcon(new javax.swing.ImageIcon("D:\\Programming Files\\CPUSchedulingSimulation\\src\\main\\java\\dark-abstract2.jpg")); // NOI18N 480 | jLabel1.setText("jLabel1"); 481 | jPanel1.add(jLabel1, new AbsoluteConstraints(0, 0, 1250, 620)); 482 | 483 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 484 | getContentPane().setLayout(layout); 485 | layout.setHorizontalGroup( 486 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 487 | .addGroup(layout.createSequentialGroup() 488 | .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 1245, javax.swing.GroupLayout.PREFERRED_SIZE) 489 | .addGap(0, 0, Short.MAX_VALUE)) 490 | ); 491 | layout.setVerticalGroup( 492 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 493 | .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 494 | ); 495 | 496 | pack(); 497 | }// //GEN-END:initComponents 498 | 499 | 500 | // Variables declaration - do not modify//GEN-BEGIN:variables 501 | private javax.swing.JLabel algoSelected2; 502 | public static javax.swing.JTextField avgServeField; 503 | private javax.swing.JLabel avgServeLabel; 504 | private javax.swing.JLabel avgTurnLabel1; 505 | public static javax.swing.JTextField avgWaitField; 506 | private javax.swing.JLabel bst1; 507 | private javax.swing.JLabel bst10; 508 | private javax.swing.JLabel bst11; 509 | private javax.swing.JLabel bst12; 510 | private javax.swing.JLabel bst13; 511 | private javax.swing.JLabel bst14; 512 | private javax.swing.JLabel bst15; 513 | private javax.swing.JLabel bst16; 514 | private javax.swing.JLabel bst17; 515 | private javax.swing.JLabel bst18; 516 | private javax.swing.JLabel bst19; 517 | private javax.swing.JLabel bst2; 518 | private javax.swing.JLabel bst20; 519 | private javax.swing.JLabel bst3; 520 | private javax.swing.JLabel bst4; 521 | private javax.swing.JLabel bst5; 522 | private javax.swing.JLabel bst6; 523 | private javax.swing.JLabel bst7; 524 | private javax.swing.JLabel bst8; 525 | private javax.swing.JLabel bst9; 526 | private javax.swing.JLabel jLabel1; 527 | private javax.swing.JLabel jLabel10; 528 | private javax.swing.JLabel jLabel11; 529 | private javax.swing.JLabel jLabel12; 530 | private javax.swing.JLabel jLabel13; 531 | private javax.swing.JLabel jLabel14; 532 | private javax.swing.JLabel jLabel15; 533 | private javax.swing.JLabel jLabel16; 534 | private javax.swing.JLabel jLabel17; 535 | private javax.swing.JLabel jLabel18; 536 | private javax.swing.JLabel jLabel2; 537 | private javax.swing.JLabel jLabel3; 538 | private javax.swing.JLabel jLabel4; 539 | private javax.swing.JLabel jLabel5; 540 | private javax.swing.JLabel jLabel6; 541 | private javax.swing.JLabel jLabel7; 542 | private javax.swing.JLabel jLabel8; 543 | private javax.swing.JLabel jLabel9; 544 | private javax.swing.JPanel jPanel1; 545 | private javax.swing.JProgressBar jProgressBar1; 546 | private javax.swing.JProgressBar jProgressBar10; 547 | private javax.swing.JProgressBar jProgressBar2; 548 | private javax.swing.JProgressBar jProgressBar3; 549 | private javax.swing.JProgressBar jProgressBar4; 550 | private javax.swing.JProgressBar jProgressBar5; 551 | private javax.swing.JProgressBar jProgressBar6; 552 | private javax.swing.JProgressBar jProgressBar7; 553 | private javax.swing.JProgressBar jProgressBar8; 554 | private javax.swing.JProgressBar jProgressBar9; 555 | private javax.swing.JScrollPane jScrollPane1; 556 | private javax.swing.JTextArea jTextArea1; 557 | private javax.swing.JLabel pt1; 558 | private javax.swing.JLabel pt10; 559 | private javax.swing.JLabel pt2; 560 | private javax.swing.JLabel pt3; 561 | private javax.swing.JLabel pt4; 562 | private javax.swing.JLabel pt5; 563 | private javax.swing.JLabel pt6; 564 | private javax.swing.JLabel pt7; 565 | private javax.swing.JLabel pt8; 566 | private javax.swing.JLabel pt9; 567 | private javax.swing.JTextField selectedAlgo; 568 | private javax.swing.JTextField selectedJob; 569 | public static javax.swing.JTextField totalExecField; 570 | // End of variables declaration//GEN-END:variables 571 | } 572 | -------------------------------------------------------------------------------- /src/main/java/CalcSimulation.form: -------------------------------------------------------------------------------- 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 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 866 | 867 | 868 | 869 | 870 | 871 | 872 | 873 | 874 | 875 | 876 | 877 | 878 | 879 | 880 | 881 | 882 | 883 | 884 | 885 | 886 | 887 | 888 | 889 | 890 | 891 | 892 | 893 | 894 | 895 | 896 | 897 | 898 | 899 | 900 | 901 | 902 | 903 | 904 | 905 | 906 | 907 | 908 | 909 | 910 | 911 | 912 | 913 | 914 | 915 | 916 | 917 | 918 | 919 | 920 | 921 | 922 | 923 | 924 | 925 | 926 | 927 | 928 | 929 | 930 | 931 | 932 | 933 | 934 | 935 | 936 | 937 | 938 | 939 | 940 | 941 | 942 | 943 | 944 | 945 | 946 | 947 | 948 | 949 | 950 | 951 | 952 | 953 | 954 | 955 | 956 | 957 | 958 | 959 | 960 | 961 | 962 | 963 | 964 | 965 | 966 | 967 | 968 | 969 | 970 | 971 | 972 | 973 | 974 | 975 | 976 | 977 | 978 | 979 | 980 | 981 | 982 | 983 | 984 | 985 | 986 | 987 | 988 | 989 | 990 | 991 | 992 | 993 | 994 | 995 | 996 | 997 | 998 | 999 | 1000 | 1001 | 1002 | 1003 | 1004 | 1005 | 1006 | 1007 | 1008 | 1009 | 1010 | 1011 | 1012 | 1013 | 1014 | 1015 | 1016 | 1017 | 1018 | 1019 | 1020 | 1021 | 1022 | 1023 | 1024 | 1025 | 1026 | 1027 | 1028 | 1029 | 1030 | 1031 | 1032 | 1033 | 1034 | 1035 | 1036 | 1037 | 1038 | 1039 | 1040 | 1041 | 1042 | 1043 | 1044 | 1045 | 1046 | 1047 | 1048 | 1049 | 1050 | 1051 | 1052 | 1053 | 1054 | 1055 | 1056 | 1057 | 1058 | 1059 | 1060 | 1061 | 1062 | 1063 | 1064 | 1065 | 1066 | 1067 | 1068 | 1069 | 1070 | 1071 | 1072 | --------------------------------------------------------------------------------