├── README ├── 主界面.png ├── 模拟结束.png └── 结果预览.png ├── out ├── testFile │ └── grab.txt └── main │ ├── Runner.class │ ├── controller │ ├── Main.class │ ├── Memory.class │ ├── Memory$Zone.class │ ├── MainFrameController.class │ ├── MainFrameController$1.class │ ├── MainFrameController$10.class │ ├── MainFrameController$11.class │ ├── MainFrameController$12.class │ ├── MainFrameController$2.class │ ├── MainFrameController$3.class │ ├── MainFrameController$4.class │ ├── MainFrameController$5.class │ ├── MainFrameController$6.class │ ├── MainFrameController$7.class │ ├── MainFrameController$8.class │ └── MainFrameController$9.class │ ├── view │ ├── MainFrame.class │ └── mainFrame.jfd │ ├── utils │ ├── ProcessSort.class │ ├── ProcessSort$1.class │ ├── ProcessSort$2.class │ └── ProcessStatus.class │ ├── process │ └── ProcessData.class │ └── model │ ├── CurProcessTableModel.class │ ├── BlockProcessTableModel.class │ ├── InputProcessTableModel.class │ ├── ReadyProcessTableModel.class │ └── OutputProcessTableModel.class ├── src ├── testFile │ └── grab.txt └── main │ ├── utils │ ├── ProcessStatus.java │ └── ProcessSort.java │ ├── Runner.java │ ├── controller │ ├── Main.java │ ├── Memory.java │ └── MainFrameController.java │ ├── model │ ├── InputProcessTableModel.java │ ├── CurProcessTableModel.java │ ├── BlockProcessTableModel.java │ ├── ReadyProcessTableModel.java │ └── OutputProcessTableModel.java │ ├── process │ └── ProcessData.java │ └── view │ ├── mainFrame.jfd │ └── MainFrame.java ├── lib ├── miglayout-core.jar ├── miglayout-swing.jar ├── miglayout-core-javadoc.jar ├── miglayout-core-sources.jar ├── miglayout-swing-javadoc.jar └── miglayout-swing-sources.jar ├── .idea ├── encodings.xml ├── vcs.xml ├── modules.xml ├── misc.xml ├── libraries │ └── MigLayout.xml ├── ProcessDispatch.iml └── workspace.xml ├── processDispatch.iml └── README.md /README/主界面.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/README/主界面.png -------------------------------------------------------------------------------- /README/模拟结束.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/README/模拟结束.png -------------------------------------------------------------------------------- /README/结果预览.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/README/结果预览.png -------------------------------------------------------------------------------- /out/testFile/grab.txt: -------------------------------------------------------------------------------- 1 | P1 0 10 4 1 2 | P2 1 1 6 1 3 | P3 2 2 2 1 4 | P4 3 1 3 1 5 | P5 4 5 6 1 -------------------------------------------------------------------------------- /src/testFile/grab.txt: -------------------------------------------------------------------------------- 1 | P1 0 10 4 1 2 | P2 1 1 6 1 3 | P3 2 2 2 1 4 | P4 3 1 3 1 5 | P5 4 5 6 1 -------------------------------------------------------------------------------- /out/main/Runner.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/Runner.class -------------------------------------------------------------------------------- /lib/miglayout-core.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/lib/miglayout-core.jar -------------------------------------------------------------------------------- /lib/miglayout-swing.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/lib/miglayout-swing.jar -------------------------------------------------------------------------------- /lib/miglayout-core-javadoc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/lib/miglayout-core-javadoc.jar -------------------------------------------------------------------------------- /lib/miglayout-core-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/lib/miglayout-core-sources.jar -------------------------------------------------------------------------------- /lib/miglayout-swing-javadoc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/lib/miglayout-swing-javadoc.jar -------------------------------------------------------------------------------- /lib/miglayout-swing-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/lib/miglayout-swing-sources.jar -------------------------------------------------------------------------------- /out/main/controller/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/controller/Main.class -------------------------------------------------------------------------------- /out/main/view/MainFrame.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/view/MainFrame.class -------------------------------------------------------------------------------- /out/main/controller/Memory.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/controller/Memory.class -------------------------------------------------------------------------------- /out/main/utils/ProcessSort.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/utils/ProcessSort.class -------------------------------------------------------------------------------- /out/main/process/ProcessData.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/process/ProcessData.class -------------------------------------------------------------------------------- /out/main/utils/ProcessSort$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/utils/ProcessSort$1.class -------------------------------------------------------------------------------- /out/main/utils/ProcessSort$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/utils/ProcessSort$2.class -------------------------------------------------------------------------------- /out/main/utils/ProcessStatus.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/utils/ProcessStatus.class -------------------------------------------------------------------------------- /out/main/controller/Memory$Zone.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/controller/Memory$Zone.class -------------------------------------------------------------------------------- /out/main/model/CurProcessTableModel.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/model/CurProcessTableModel.class -------------------------------------------------------------------------------- /out/main/model/BlockProcessTableModel.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/model/BlockProcessTableModel.class -------------------------------------------------------------------------------- /out/main/model/InputProcessTableModel.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/model/InputProcessTableModel.class -------------------------------------------------------------------------------- /out/main/model/ReadyProcessTableModel.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/model/ReadyProcessTableModel.class -------------------------------------------------------------------------------- /out/main/controller/MainFrameController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/controller/MainFrameController.class -------------------------------------------------------------------------------- /out/main/model/OutputProcessTableModel.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/model/OutputProcessTableModel.class -------------------------------------------------------------------------------- /out/main/controller/MainFrameController$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/controller/MainFrameController$1.class -------------------------------------------------------------------------------- /out/main/controller/MainFrameController$10.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/controller/MainFrameController$10.class -------------------------------------------------------------------------------- /out/main/controller/MainFrameController$11.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/controller/MainFrameController$11.class -------------------------------------------------------------------------------- /out/main/controller/MainFrameController$12.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/controller/MainFrameController$12.class -------------------------------------------------------------------------------- /out/main/controller/MainFrameController$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/controller/MainFrameController$2.class -------------------------------------------------------------------------------- /out/main/controller/MainFrameController$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/controller/MainFrameController$3.class -------------------------------------------------------------------------------- /out/main/controller/MainFrameController$4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/controller/MainFrameController$4.class -------------------------------------------------------------------------------- /out/main/controller/MainFrameController$5.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/controller/MainFrameController$5.class -------------------------------------------------------------------------------- /out/main/controller/MainFrameController$6.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/controller/MainFrameController$6.class -------------------------------------------------------------------------------- /out/main/controller/MainFrameController$7.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/controller/MainFrameController$7.class -------------------------------------------------------------------------------- /out/main/controller/MainFrameController$8.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/controller/MainFrameController$8.class -------------------------------------------------------------------------------- /out/main/controller/MainFrameController$9.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xubaigame/ProcessDispatch/HEAD/out/main/controller/MainFrameController$9.class -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/main/utils/ProcessStatus.java: -------------------------------------------------------------------------------- 1 | package main.utils; 2 | 3 | /** 4 | * @Auther: Administrator 5 | * @Date: 2018/11/3 15:37 6 | * @Description: 7 | */ 8 | public enum ProcessStatus { 9 | RUNNING,READY,BLOCKED,FINISH 10 | } -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | -------------------------------------------------------------------------------- /src/main/Runner.java: -------------------------------------------------------------------------------- 1 | package main; 2 | 3 | import main.controller.MainFrameController; 4 | 5 | /** 6 | * @Auther: Administrator 7 | * @Date: 2018/11/2 13:46 8 | * @Description: 9 | */ 10 | public class Runner { 11 | 12 | public static void main(String[] args) { 13 | MainFrameController mainFrameController = new MainFrameController(); 14 | 15 | mainFrameController.showMainFrameWindow(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /processDispatch.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/MigLayout.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/ProcessDispatch.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 基于优先级的非抢占/抢占进程调度算法模拟程序 2 | 3 | **作者:积极向上小木木             联系方式:PositiveMumu@126.com** 4 | 5 | *该项目仅仅实现基于优先级的两种进程调度算法,其余四种不支持* 6 | 7 | [TOC] 8 | 9 | ## 一、程序功能 10 | 1. 新建进程前,请初始化打印机数量,默认为0。 11 | 2. 程序可手动创建模拟进程序列,也可从文件导入。创建或导入的进程列表在新建进程列表中显示。 12 | 3. 通过文件导入进程信息可以参考testFile目录下的grab.txt文件。 13 | 4. 选择模拟的方法: 14 | 1. 非抢占式。 15 | 2. 抢占式。 16 | 5. 在模拟运行过程中,可以对当前进程进行阻塞,也可以在阻塞队列中唤醒进程。 17 | 6. 在运行过程中可随时暂停模拟,观察结果。验证完毕后可以继续模拟。 18 | 7. 模拟结束后可在预览窗口查看模拟运行结果。包括运行时间,周转时间,带权周转时间等信息。 19 | 8. 可在主界面重置程序进行下一次模拟,也可随时退出程序。 20 | 21 | ## 二、项目信息 22 | 23 | 1. 项目使用IDEA_2017.3.5完成。 24 | 25 | 2. 在本项目中,笔者为IDEA添加了JFormDesigner插件,制作与修改客户端各个页面时需要用到这个插件。插件的安装及破解请自行百度。(后续会考虑出教程) 26 | 27 | 3. JDK版本为1.8_211。 28 | 29 | ## 三、程序截图 30 | 1. 主界面: 31 | 32 | ![主界面](README/主界面.png) 33 | 34 | 2. 模拟结束: 35 | 36 | ![模拟结束](README/模拟结束.png) 37 | 38 | 3.结果预览: 39 | 40 | ![结果预览](README/结果预览.png) 41 | -------------------------------------------------------------------------------- /src/main/controller/Main.java: -------------------------------------------------------------------------------- 1 | package main.controller; 2 | 3 | import java.util.Scanner; 4 | 5 | /** 6 | * @Date: 2018/11/18 10:17 7 | * @Description: 8 | */ 9 | public class Main { 10 | 11 | public static void main(String[] args) { 12 | Memory memory = null; 13 | Scanner in = new Scanner(System.in); 14 | System.out.print("请初始化内存大小:"); 15 | int size = in.nextInt(); 16 | memory = new Memory(size); 17 | memory.showZones(); 18 | while (true){ 19 | System.out.println("1.申请空间 2.回收空间 3.显示分区状况"); 20 | System.out.print("请选择指令:"); 21 | size = in.nextInt(); 22 | switch (size) { 23 | case 1: 24 | System.out.print("请输入需要申请的空间大小:"); 25 | size = in.nextInt(); 26 | memory.allocation(size); 27 | break; 28 | case 2: 29 | System.out.print("请输入需要回收的分区号:"); 30 | size = in.nextInt(); 31 | memory.collection(size); 32 | break; 33 | case 3: 34 | memory.showZones(); 35 | break; 36 | default: 37 | System.out.println("请重新选择!"); 38 | } 39 | } 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /src/main/model/InputProcessTableModel.java: -------------------------------------------------------------------------------- 1 | package main.model; 2 | 3 | import main.process.ProcessData; 4 | 5 | import javax.swing.table.AbstractTableModel; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * @Auther: Administrator 11 | * @Date: 2018/11/2 22:44 12 | * @Description: 13 | */ 14 | public class InputProcessTableModel extends AbstractTableModel { 15 | private String[] columnNames = {"进程名", "到达时间", "服务时间", "进程优先数","使用打印机数", }; 16 | private List inputProcessQueue = new ArrayList<>(); 17 | 18 | public void addProcess(ProcessData process) { 19 | inputProcessQueue.add(process); 20 | } 21 | 22 | public void clearProcess(){ 23 | inputProcessQueue.clear(); 24 | } 25 | 26 | @Override 27 | public int getRowCount() { 28 | return inputProcessQueue.size(); 29 | } 30 | 31 | @Override 32 | public int getColumnCount() { 33 | return columnNames.length; 34 | } 35 | 36 | @Override 37 | public String getColumnName(int columnIndex) { 38 | return columnNames[columnIndex]; 39 | } 40 | 41 | @Override 42 | public Object getValueAt(int rowIndex, int columnIndex) { 43 | ProcessData rowProcess = inputProcessQueue.get(rowIndex); 44 | switch (columnIndex) { 45 | case 0: 46 | return rowProcess.getName(); 47 | case 1: 48 | return rowProcess.getArriveTime(); 49 | case 2: 50 | return rowProcess.getNeedTime(); 51 | case 3: 52 | return rowProcess.getPrio(); 53 | case 4: 54 | return rowProcess.getPrinterReq(); 55 | } 56 | return null; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/model/CurProcessTableModel.java: -------------------------------------------------------------------------------- 1 | package main.model; 2 | 3 | import main.process.ProcessData; 4 | 5 | import javax.swing.table.AbstractTableModel; 6 | 7 | /** 8 | * @Auther: Administrator 9 | * @Date: 2018/11/2 22:44 10 | * @Description: 11 | */ 12 | public class CurProcessTableModel extends AbstractTableModel { 13 | private String[] columnNames = {"进程名", "到达时间", "服务时间", "开始时间", "进程优先数", "占用打印机数", "剩余执行时间"}; 14 | private ProcessData currentProcess = null; 15 | 16 | public void setCurrentProcess(ProcessData currentProcess) { 17 | this.currentProcess = currentProcess; 18 | } 19 | 20 | 21 | @Override 22 | public int getRowCount() { 23 | if(currentProcess!=null) 24 | return 1; 25 | else return 0; 26 | } 27 | 28 | @Override 29 | public int getColumnCount() { 30 | return columnNames.length; 31 | } 32 | 33 | @Override 34 | public String getColumnName(int columnIndex) { 35 | return columnNames[columnIndex]; 36 | } 37 | 38 | @Override 39 | public Object getValueAt(int rowIndex, int columnIndex) { 40 | switch (columnIndex){ 41 | case 0: 42 | return currentProcess.getName(); 43 | case 1: 44 | return currentProcess.getArriveTime(); 45 | case 2: 46 | return currentProcess.getNeedTime(); 47 | case 3: 48 | return currentProcess.getBeginTime()!=-1? currentProcess.getBeginTime():"\\"; 49 | case 4: 50 | return currentProcess.getPrio(); 51 | case 5: 52 | return currentProcess.getPrinterReq(); 53 | case 6: 54 | return currentProcess.getMoreTime(); 55 | 56 | } 57 | return null; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/model/BlockProcessTableModel.java: -------------------------------------------------------------------------------- 1 | package main.model; 2 | 3 | import main.process.ProcessData; 4 | 5 | import javax.swing.table.AbstractTableModel; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * @Auther: Administrator 11 | * @Date: 2018/11/2 22:44 12 | * @Description: 13 | */ 14 | public class BlockProcessTableModel extends AbstractTableModel { 15 | private String[] columnNames = {"进程名", "到达时间", "服务时间", "开始时间","进程优先数", "占用打印机数", "剩余执行时间"}; 16 | private List blockProcessQueue = new ArrayList<>(); 17 | 18 | public void setProcessQueue(List processQueue) { 19 | blockProcessQueue = processQueue; 20 | } 21 | 22 | @Override 23 | public int getRowCount() { 24 | return blockProcessQueue.size(); 25 | } 26 | 27 | @Override 28 | public int getColumnCount() { 29 | return columnNames.length; 30 | } 31 | 32 | @Override 33 | public String getColumnName(int columnIndex) { 34 | return columnNames[columnIndex]; 35 | } 36 | 37 | @Override 38 | public Object getValueAt(int rowIndex, int columnIndex) { 39 | ProcessData rowProcess = blockProcessQueue.get(rowIndex); 40 | switch (columnIndex) { 41 | case 0: 42 | return rowProcess.getName(); 43 | case 1: 44 | return rowProcess.getArriveTime(); 45 | case 2: 46 | return rowProcess.getNeedTime(); 47 | case 3: 48 | return rowProcess.getBeginTime()!=-1? rowProcess.getBeginTime():"\\"; 49 | case 4: 50 | return rowProcess.getPrio(); 51 | case 5: 52 | return rowProcess.getPrinterReq(); 53 | case 6: 54 | return rowProcess.getMoreTime(); 55 | 56 | } 57 | return null; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/model/ReadyProcessTableModel.java: -------------------------------------------------------------------------------- 1 | package main.model; 2 | 3 | import main.process.ProcessData; 4 | 5 | import javax.swing.table.AbstractTableModel; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * @Auther: Administrator 11 | * @Date: 2018/11/2 22:44 12 | * @Description: 13 | */ 14 | public class ReadyProcessTableModel extends AbstractTableModel { 15 | private String[] columnNames = {"进程名", "到达时间", "服务时间", "开始时间", "进程优先数", "占用打印机数", "剩余执行时间"}; 16 | private List readyProcessQueue = new ArrayList<>(); 17 | 18 | public void setProcessQueue(List processQueue) { 19 | readyProcessQueue = processQueue; 20 | } 21 | 22 | @Override 23 | public int getRowCount() { 24 | return readyProcessQueue.size(); 25 | } 26 | 27 | @Override 28 | public int getColumnCount() { 29 | return columnNames.length; 30 | } 31 | 32 | @Override 33 | public String getColumnName(int columnIndex) { 34 | return columnNames[columnIndex]; 35 | } 36 | 37 | @Override 38 | public Object getValueAt(int rowIndex, int columnIndex) { 39 | ProcessData rowProcess = readyProcessQueue.get(rowIndex); 40 | switch (columnIndex){ 41 | case 0: 42 | return rowProcess.getName(); 43 | case 1: 44 | return rowProcess.getArriveTime(); 45 | case 2: 46 | return rowProcess.getNeedTime(); 47 | case 3: 48 | return rowProcess.getBeginTime()!=-1? rowProcess.getBeginTime():"\\"; 49 | case 4: 50 | return rowProcess.getPrio(); 51 | case 5: 52 | return rowProcess.getPrinterReq(); 53 | case 6: 54 | return rowProcess.getMoreTime(); 55 | 56 | } 57 | return null; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/utils/ProcessSort.java: -------------------------------------------------------------------------------- 1 | package main.utils; 2 | 3 | import main.process.ProcessData; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Collections; 7 | import java.util.Comparator; 8 | import java.util.List; 9 | 10 | /** 11 | * @Auther: Administrator 12 | * @Date: 2018/11/2 15:12 13 | * @Description: 14 | */ 15 | public class ProcessSort { 16 | 17 | public static void sortByPriority(List processDataList){ 18 | // 根据优先级排序 19 | Collections.sort(processDataList, new Comparator() { 20 | @Override 21 | public int compare(ProcessData p1, ProcessData p2) { 22 | if(p1.getArriveTime()==p2.getArriveTime()) 23 | // 优先级相同先来先服务 24 | return p1.getId() - p2.getId(); 25 | // 数大优先级高 26 | return p2.getPrio() - p1.getPrio(); 27 | } 28 | }); 29 | } 30 | public static void sortByArriveTime(List processDataList){ 31 | // 根据优先级排序 32 | Collections.sort(processDataList, new Comparator() { 33 | @Override 34 | public int compare(ProcessData p1, ProcessData p2) { 35 | // 按到达时间升序排列 36 | if(p1.getArriveTime()==p2.getArriveTime()) 37 | // 到达时间相同先来先服务 38 | return p1.getId() - p2.getId(); 39 | return p1.getArriveTime() - p2.getArriveTime(); 40 | } 41 | }); 42 | } 43 | 44 | public static void main(String[] args) { 45 | List processDataList = new ArrayList<>(); 46 | sortByPriority(processDataList); 47 | System.out.println(processDataList.remove(0)); 48 | 49 | for(ProcessData processData:processDataList){ 50 | System.out.println(processData); 51 | } 52 | } 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/model/OutputProcessTableModel.java: -------------------------------------------------------------------------------- 1 | package main.model; 2 | 3 | import main.process.ProcessData; 4 | 5 | import javax.swing.table.AbstractTableModel; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * @Auther: Administrator 11 | * @Date: 2018/11/2 22:44 12 | * @Description: 13 | */ 14 | public class OutputProcessTableModel extends AbstractTableModel { 15 | private String[] columnNames = {"进程名", "到达时间", "服务时间", "进程优先数", "开始时间", "完成时间", "周转时间", "带权周转时间" }; 16 | private List outputProcessQueue = new ArrayList<>(); 17 | 18 | public void setProcessQueue(List processQueue) { 19 | outputProcessQueue = processQueue; 20 | } 21 | 22 | @Override 23 | public int getRowCount() { 24 | return outputProcessQueue.size(); 25 | } 26 | 27 | @Override 28 | public int getColumnCount() { 29 | return columnNames.length; 30 | } 31 | 32 | @Override 33 | public String getColumnName(int columnIndex) { 34 | return columnNames[columnIndex]; 35 | } 36 | 37 | @Override 38 | public Object getValueAt(int rowIndex, int columnIndex) { 39 | ProcessData rowProcess = outputProcessQueue.get(rowIndex); 40 | switch (columnIndex) { 41 | case 0: 42 | return rowProcess.getName(); 43 | case 1: 44 | return rowProcess.getArriveTime(); 45 | case 2: 46 | return rowProcess.getNeedTime(); 47 | case 3: 48 | return rowProcess.getPrio(); 49 | case 4: 50 | return rowProcess.getBeginTime(); 51 | case 5: 52 | return rowProcess.getFinishTime(); 53 | case 6: 54 | return rowProcess.getFinishTime() - rowProcess.getArriveTime(); 55 | case 7: 56 | return Math.round(1.0 * (rowProcess.getFinishTime() - rowProcess.getArriveTime()) / rowProcess.getNeedTime() * 100) /100.0; 57 | 58 | } 59 | return null; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/process/ProcessData.java: -------------------------------------------------------------------------------- 1 | package main.process; 2 | 3 | import main.utils.ProcessStatus; 4 | 5 | /** 6 | * @Auther: Administrator 7 | * @Date: 2018/11/2 14:49 8 | * @Description: 9 | */ 10 | public class ProcessData { 11 | private static int count=0; 12 | private String name;//进程名 13 | private int id=0;//进程标识数 14 | private int arriveTime;//到达时间 15 | private int needTime;//服务时间 16 | private int prio;//进程优先数,数字越大优先级越高 17 | private int moreTime; //剩余执行的时间 18 | private int beginTime; // 开始时间 19 | private int finishTime; // 完成时间 20 | private ProcessStatus status; //进程状态 4种状态:执行--0、就绪--1、阻塞--2、完成--3 21 | 22 | // 请求打印机数 23 | private int printerReq; 24 | 25 | public ProcessData(String name, int arriveTime, int needTime, int prio, int printerReq) { 26 | this.name = name; 27 | this.arriveTime = arriveTime; 28 | this.needTime = needTime; 29 | this.prio = prio; 30 | this.printerReq = printerReq; 31 | moreTime = needTime; 32 | // 初始状态 33 | beginTime = -1; 34 | id = count++; 35 | 36 | } 37 | 38 | public int getPrio() { 39 | return prio; 40 | } 41 | 42 | public int getArriveTime() { 43 | return arriveTime; 44 | } 45 | 46 | public String getName() { 47 | return name; 48 | } 49 | 50 | public int getNeedTime() { 51 | return needTime; 52 | } 53 | 54 | public int getMoreTime() { 55 | return moreTime; 56 | } 57 | 58 | public int getPrinterReq() { 59 | return printerReq; 60 | } 61 | 62 | public int getBeginTime() { 63 | return beginTime; 64 | } 65 | 66 | public void setBeginTime(int beginTime) { 67 | this.beginTime = beginTime; 68 | } 69 | 70 | public ProcessStatus getStatus() { 71 | return status; 72 | } 73 | 74 | public void setStatus(ProcessStatus status) { 75 | this.status = status; 76 | } 77 | 78 | public int getFinishTime() { 79 | return finishTime; 80 | } 81 | 82 | public void setFinishTime(int finishTime) { 83 | this.finishTime = finishTime; 84 | } 85 | 86 | public void subMoreTime(){ 87 | moreTime -=1; 88 | } 89 | 90 | public void addMoreTime(){ 91 | moreTime +=1; 92 | } 93 | 94 | public boolean isFinished(){ 95 | if(moreTime <=0) 96 | return true; 97 | else 98 | return false; 99 | } 100 | 101 | public int getId() { 102 | return id; 103 | } 104 | 105 | public String toString(){ 106 | return "name: " + name + " arriveTime: " + arriveTime + " needTime: " + needTime + " sortByPriority: " + prio + " moreTime: " + moreTime; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 11 | 12 | 14 | 15 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 47 | 48 | 59 | 60 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 1570523448808 90 | 115 | 116 | 117 | 118 | 120 | 121 | 132 | 133 | -------------------------------------------------------------------------------- /src/main/controller/Memory.java: -------------------------------------------------------------------------------- 1 | package main.controller; 2 | 3 | /** 4 | * @Date: 2018/11/18 10:14 5 | * @Description: 6 | */ 7 | import java.util.LinkedList; 8 | import java.util.Scanner; 9 | 10 | /** 11 | * 内存类 12 | * @author dht925nerd@126.com 13 | */ 14 | public class Memory{ 15 | /** 16 | * 内存大小 17 | */ 18 | private int size; 19 | /** 20 | * 最小剩余分区大小 21 | */ 22 | private static final int MIN_SIZE = 5; 23 | /** 24 | * 内存分区 25 | */ 26 | private LinkedList zones; 27 | /** 28 | * 上次分配的空闲区位置 29 | */ 30 | private int pointer; 31 | 32 | /** 33 | * 分区节点类 34 | */ 35 | class Zone{ 36 | /** 37 | * 分区大小 38 | */ 39 | private int size; 40 | /** 41 | * 分区始址 42 | */ 43 | private int head; 44 | /** 45 | * 空闲状态 46 | */ 47 | private boolean isFree; 48 | 49 | public Zone(int head, int size) { 50 | this.head = head; 51 | this.size = size; 52 | this.isFree = true; 53 | } 54 | } 55 | 56 | /** 57 | * 默认内存大小为 100 KB 58 | */ 59 | public Memory(){ 60 | this.size = 100; 61 | this.pointer = 0; 62 | this.zones = new LinkedList<>(); 63 | zones.add(new Zone(0, size)); 64 | } 65 | public Memory(int size) { 66 | this.size = size; 67 | this.pointer = 0; 68 | this.zones = new LinkedList<>(); 69 | zones.add(new Zone(0, size)); 70 | } 71 | 72 | /** 73 | * 内存分配 74 | * @param size 指定需要分配的大小 75 | */ 76 | public void allocation(int size){ 77 | // 使用首次适应算法 78 | fristFit(size); 79 | // System.out.println("1.FirstFit 2.NextFit 3.BestFit 4.WorstFit"); 80 | // System.out.print("请选择分配算法:"); 81 | // Scanner in = new Scanner(System.in); 82 | // int algorithm = in.nextInt(); 83 | // switch (algorithm){ 84 | // case 1: 85 | // fristFit(size);break; 86 | // case 2: 87 | // nextFit(size);break; 88 | // case 3: 89 | // bestFit(size);break; 90 | // case 4: 91 | // worstFit(size);break; 92 | // default: 93 | // System.out.println("请重新选择!"); 94 | // } 95 | } 96 | 97 | /** 98 | * 首次适应算法 99 | * @param size 指定需要分配的大小 100 | */ 101 | private void fristFit(int size){ 102 | //遍历分区链表 103 | // pointer 上次分配的空闲区位置 104 | // 记录当前剩余可用分区总大小 105 | int remainSize = 0; 106 | for (pointer = 0; pointer < zones.size(); pointer++){ 107 | Zone tmp = zones.get(pointer); 108 | if(tmp.isFree) 109 | remainSize += tmp.size; 110 | //找到可用分区(空闲且大小足够) 111 | if (tmp.isFree && (tmp.size > size)){ 112 | doAllocation(size, pointer, tmp); 113 | return; 114 | } 115 | } 116 | //遍历结束后未找到可用分区 117 | // 判断当前剩余可用分区大小 118 | System.out.println("当前剩余可用分区总大小: " + remainSize); 119 | 120 | System.out.println("无可用内存空间!"); 121 | } 122 | 123 | /** 124 | * 循环首次适应算法 125 | * @param size 指定需要分配的大小 126 | */ 127 | private void nextFit(int size){ 128 | //从上次分配空闲区位置开始遍历分区链表 129 | Zone tmp = zones.get(pointer); 130 | if (tmp.isFree && (tmp.size > size)){ 131 | doAllocation(size, pointer, tmp); 132 | return; 133 | } 134 | int len = zones.size(); 135 | int i = (pointer + 1) % len; 136 | for (; i != pointer; i = (i+1) % len){ 137 | tmp = zones.get(i); 138 | //找到可用分区(空闲且大小足够) 139 | if (tmp.isFree && (tmp.size > size)){ 140 | doAllocation(size, i, tmp); 141 | return; 142 | } 143 | } 144 | //遍历结束后未找到可用分区, 则内存分配失败 145 | System.out.println("无可用内存空间!"); 146 | } 147 | 148 | /** 149 | * 最佳适应算法 150 | * @param size 指定需要分配的大小 151 | */ 152 | private void bestFit(int size){ 153 | int flag = -1; 154 | int min = this.size; 155 | for (pointer = 0; pointer < zones.size(); pointer++){ 156 | Zone tmp = zones.get(pointer); 157 | if (tmp.isFree && (tmp.size > size)){ 158 | if (min > tmp.size - size){ 159 | min = tmp.size - size; 160 | flag = pointer; 161 | } 162 | } 163 | } 164 | if (flag == -1){ 165 | System.out.println("无可用内存空间!"); 166 | }else { 167 | doAllocation(size, flag, zones.get(flag)); 168 | } 169 | } 170 | 171 | /** 172 | * 最坏适应算法 173 | * @param size 指定需要分配的大小 174 | */ 175 | private void worstFit(int size){ 176 | int flag = -1; 177 | int max = 0; 178 | for (pointer = 0; pointer < zones.size(); pointer++){ 179 | Zone tmp = zones.get(pointer); 180 | if (tmp.isFree && (tmp.size > size)){ 181 | if (max < tmp.size - size){ 182 | max = tmp.size - size; 183 | flag = pointer; 184 | } 185 | } 186 | } 187 | if (flag == -1){ 188 | System.out.println("无可用内存空间!"); 189 | }else { 190 | doAllocation(size, flag, zones.get(flag)); 191 | } 192 | } 193 | 194 | /** 195 | * 执行分配 196 | * @param size 申请大小 197 | * @param location 当前可用分区位置 198 | * @param tmp 可用空闲区 199 | */ 200 | private void doAllocation(int size, int location, Zone tmp) { 201 | //如果分割后分区剩余大小过小(MIN_SIZE)则将分区全部分配,否则分割为两个分区 202 | if (tmp.size - size <= MIN_SIZE){ 203 | tmp.isFree = false; 204 | } else { 205 | Zone split = new Zone(tmp.head + size, tmp.size - size); 206 | zones.add(location + 1, split); 207 | tmp.size = size; 208 | tmp.isFree = false; 209 | } 210 | System.out.println("成功分配 " + size + "KB 内存!"); 211 | } 212 | 213 | /** 214 | * 内存回收 215 | * @param id 指定要回收的分区好号 216 | */ 217 | public void collection(int id){ 218 | if (id >= zones.size()){ 219 | System.out.println("无此分区编号!"); 220 | return; 221 | } 222 | Zone tmp = zones.get(id); 223 | int size = tmp.size; 224 | if (tmp.isFree) { 225 | System.out.println("指定分区未被分配, 无需回收"); 226 | return; 227 | } 228 | //如果回收分区不是尾分区且后一个分区为空闲, 则与后一个分区合并 229 | if (id < zones.size() - 1 && zones.get(id + 1).isFree){ 230 | Zone next = zones.get(id + 1); 231 | tmp.size += next.size; 232 | zones.remove(next); 233 | } 234 | //如果回收分区不是首分区且前一个分区为空闲, 则与前一个分区合并 235 | if (id > 0 && zones.get(id - 1).isFree){ 236 | Zone previous = zones.get(id - 1); 237 | previous.size += tmp.size; 238 | zones.remove(id); 239 | id--; 240 | } 241 | zones.get(id).isFree = true; 242 | System.out.println("内存回收成功!, 本次回收了 " + size + "KB 空间!"); 243 | } 244 | 245 | /** 246 | * 展示内存分区状况 247 | */ 248 | public void showZones(){ 249 | System.out.println("------------------------------------"); 250 | System.out.println("分区编号\t分区始址\t分区大小\t空闲状态\t"); 251 | System.out.println("------------------------------------"); 252 | for (int i = 0; i < zones.size(); i++){ 253 | Zone tmp = zones.get(i); 254 | System.out.println(i + "\t\t" + tmp.head + "\t\t" + 255 | tmp.size + " \t" + tmp.isFree); 256 | } 257 | System.out.println("------------------------------------"); 258 | } 259 | } -------------------------------------------------------------------------------- /out/main/view/mainFrame.jfd: -------------------------------------------------------------------------------- 1 | JFDML JFormDesigner: "6.0.2.0.116" Java: "1.8.0_181" encoding: "UTF-8" 2 | 3 | new FormModel { 4 | contentType: "form/swing" 5 | root: new FormRoot { 6 | add( new FormWindow( "javax.swing.JFrame", new FormLayoutManager( class com.jformdesigner.runtime.NullLayout ) ) { 7 | name: "this" 8 | add( new FormContainer( "javax.swing.JTabbedPane", new FormLayoutManager( class javax.swing.JTabbedPane ) ) { 9 | name: "mainTabbedPane" 10 | add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class com.jformdesigner.runtime.NullLayout ) ) { 11 | name: "createProcessPanel" 12 | add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class com.jformdesigner.runtime.NullLayout ) ) { 13 | name: "panel3" 14 | "border": new javax.swing.border.EtchedBorder( 1, null, null ) 15 | add( new FormComponent( "javax.swing.JButton" ) { 16 | name: "initialBtn" 17 | "text": "设置打印机" 18 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 19 | "x": 510 20 | "y": 5 21 | "width": 115 22 | "height": 45 23 | } ) 24 | add( new FormComponent( "javax.swing.JTextField" ) { 25 | name: "printerJFT" 26 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 27 | "x": 120 28 | "y": 20 29 | "width": 64 30 | "height": 30 31 | } ) 32 | add( new FormComponent( "javax.swing.JLabel" ) { 33 | name: "label1" 34 | "text": "初始设置" 35 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 36 | "x": 5 37 | "y": 0 38 | "width": 55 39 | "height": 25 40 | } ) 41 | add( new FormComponent( "javax.swing.JLabel" ) { 42 | name: "label3" 43 | "text": "打印机" 44 | "horizontalAlignment": 0 45 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 46 | "x": 50 47 | "y": 20 48 | "width": 66 49 | "height": 27 50 | } ) 51 | add( new FormComponent( "javax.swing.JLabel" ) { 52 | name: "label5" 53 | "text": "台" 54 | "horizontalAlignment": 0 55 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 56 | "x": 180 57 | "y": 20 58 | "width": 45 59 | "height": 27 60 | } ) 61 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 62 | "x": 5 63 | "y": 10 64 | "width": 715 65 | "height": 55 66 | } ) 67 | add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class com.jformdesigner.runtime.NullLayout ) { 68 | "autoSize": false 69 | } ) { 70 | name: "panel4" 71 | "border": &EtchedBorder0 new javax.swing.border.EtchedBorder( 1, null, null ) 72 | add( new FormComponent( "javax.swing.JLabel" ) { 73 | name: "label6" 74 | "text": "新建进程" 75 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 76 | "x": 5 77 | "y": 5 78 | "width": 60 79 | } ) 80 | add( new FormComponent( "javax.swing.JLabel" ) { 81 | name: "label7" 82 | "text": "进程名称 " 83 | "horizontalAlignment": 0 84 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 85 | "x": 45 86 | "y": 20 87 | "width": 70 88 | "height": 25 89 | } ) 90 | add( new FormComponent( "javax.swing.JLabel" ) { 91 | name: "label8" 92 | "text": "提交时间" 93 | "horizontalAlignment": 0 94 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 95 | "width": 70 96 | "height": 25 97 | "x": 130 98 | "y": 20 99 | } ) 100 | add( new FormComponent( "javax.swing.JLabel" ) { 101 | name: "label9" 102 | "text": "服务时间" 103 | "horizontalAlignment": 0 104 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 105 | "width": 70 106 | "height": 25 107 | "x": 195 108 | "y": 20 109 | } ) 110 | add( new FormComponent( "javax.swing.JLabel" ) { 111 | name: "label11" 112 | "text": "打印机请求数量" 113 | "horizontalAlignment": 0 114 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 115 | "width": 105 116 | "height": 25 117 | "x": 345 118 | "y": 20 119 | } ) 120 | add( new FormComponent( "javax.swing.JTextField" ) { 121 | name: "processNameJFT" 122 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 123 | "x": 45 124 | "y": 50 125 | "height": 25 126 | "width": 69 127 | } ) 128 | add( new FormComponent( "javax.swing.JTextField" ) { 129 | name: "submitTimeJFT" 130 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 131 | "width": 64 132 | "height": 25 133 | "x": 130 134 | "y": 50 135 | } ) 136 | add( new FormComponent( "javax.swing.JTextField" ) { 137 | name: "serveTimeJFT" 138 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 139 | "width": 64 140 | "height": 25 141 | "x": 200 142 | "y": 50 143 | } ) 144 | add( new FormComponent( "javax.swing.JTextField" ) { 145 | name: "printerReqJFT" 146 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 147 | "width": 64 148 | "height": 25 149 | "x": 365 150 | "y": 50 151 | } ) 152 | add( new FormComponent( "javax.swing.JButton" ) { 153 | name: "newProcessBtn" 154 | "text": "新建进程" 155 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 156 | "x": 480 157 | "y": 20 158 | "width": 100 159 | "height": 45 160 | } ) 161 | add( new FormComponent( "javax.swing.JLabel" ) { 162 | name: "label18" 163 | "text": "优先级" 164 | "horizontalAlignment": 0 165 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 166 | "x": 275 167 | "y": 25 168 | "width": 50 169 | } ) 170 | add( new FormComponent( "javax.swing.JTextField" ) { 171 | name: "priorityJFT" 172 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 173 | "x": 275 174 | "y": 50 175 | "width": 64 176 | "height": 25 177 | } ) 178 | add( new FormComponent( "javax.swing.JButton" ) { 179 | name: "LoadFileBtn" 180 | "text": "导入文件" 181 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 182 | "width": 100 183 | "height": 45 184 | "x": 595 185 | "y": 20 186 | } ) 187 | add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) { 188 | name: "scrollPane6" 189 | add( new FormComponent( "javax.swing.JTable" ) { 190 | name: "createProcessTable" 191 | } ) 192 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 193 | "x": 15 194 | "y": 80 195 | "width": 680 196 | "height": 95 197 | } ) 198 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 199 | "x": 5 200 | "y": 60 201 | "height": 180 202 | "width": 715 203 | } ) 204 | add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class com.jformdesigner.runtime.NullLayout ) { 205 | "autoSize": false 206 | } ) { 207 | name: "panel5" 208 | "border": #EtchedBorder0 209 | add( new FormComponent( "javax.swing.JLabel" ) { 210 | name: "label12" 211 | "text": "请选择模拟方法:" 212 | "horizontalAlignment": 0 213 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 214 | "x": 15 215 | "y": 15 216 | "width": 125 217 | "height": 25 218 | } ) 219 | add( new FormComponent( "javax.swing.JRadioButton" ) { 220 | name: "noGrabRadioBtn" 221 | "text": "非抢占式优先调度" 222 | "$buttonGroup": new FormReference( "buttonGroup1" ) 223 | "selected": true 224 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 225 | "x": 165 226 | "y": 15 227 | "width": 140 228 | } ) 229 | add( new FormComponent( "javax.swing.JRadioButton" ) { 230 | name: "grabRadioBtnButton2" 231 | "text": "抢占式优先调度" 232 | "$buttonGroup": new FormReference( "buttonGroup1" ) 233 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 234 | "width": 140 235 | "height": 19 236 | "x": 340 237 | "y": 20 238 | } ) 239 | add( new FormComponent( "javax.swing.JButton" ) { 240 | name: "startBtn" 241 | "text": "开始模拟" 242 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 243 | "x": 530 244 | "y": 10 245 | "width": 110 246 | "height": 35 247 | } ) 248 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 249 | "x": 5 250 | "y": 240 251 | "height": 50 252 | "width": 715 253 | } ) 254 | add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class com.jformdesigner.runtime.NullLayout ) { 255 | "autoSize": false 256 | } ) { 257 | name: "panel6" 258 | "border": #EtchedBorder0 259 | add( new FormComponent( "javax.swing.JLabel" ) { 260 | name: "label13" 261 | "text": "运行进程队列" 262 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 263 | "x": 5 264 | "y": 5 265 | "width": 120 266 | "height": 25 267 | } ) 268 | add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) { 269 | name: "scrollPane1" 270 | add( new FormComponent( "javax.swing.JTable" ) { 271 | name: "currentProcessTable" 272 | } ) 273 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 274 | "x": 15 275 | "y": 40 276 | "width": 605 277 | "height": 40 278 | } ) 279 | add( new FormComponent( "javax.swing.JLabel" ) { 280 | name: "label19" 281 | "text": "当前时间:" 282 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 283 | "x": 150 284 | "y": 10 285 | "width": 75 286 | } ) 287 | add( new FormComponent( "javax.swing.JLabel" ) { 288 | name: "currentTimeJFT" 289 | "horizontalAlignment": 2 290 | "text": "0" 291 | "font": &Font0 new java.awt.Font( "Microsoft YaHei UI", 0, 13 ) 292 | "verticalAlignment": 1 293 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 294 | "x": 220 295 | "y": 10 296 | "width": 50 297 | "height": 20 298 | } ) 299 | add( new FormComponent( "javax.swing.JLabel" ) { 300 | name: "label24" 301 | "text": "当前剩余打印机数:" 302 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 303 | "x": 295 304 | "y": 10 305 | "width": 125 306 | } ) 307 | add( new FormComponent( "javax.swing.JLabel" ) { 308 | name: "currentPrinterJFT" 309 | "text": "0" 310 | "horizontalAlignment": 2 311 | "verticalAlignment": 1 312 | "font": #Font0 313 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 314 | "x": 415 315 | "y": 10 316 | "width": 50 317 | "height": 20 318 | } ) 319 | add( new FormComponent( "javax.swing.JButton" ) { 320 | name: "blockBtn" 321 | "text": "阻塞" 322 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 323 | "x": 630 324 | "y": 30 325 | "width": 75 326 | "height": 50 327 | } ) 328 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 329 | "x": 5 330 | "y": 285 331 | "height": 110 332 | "width": 715 333 | } ) 334 | add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class com.jformdesigner.runtime.NullLayout ) { 335 | "autoSize": false 336 | } ) { 337 | name: "panel7" 338 | "border": #EtchedBorder0 339 | add( new FormComponent( "javax.swing.JLabel" ) { 340 | name: "label14" 341 | "text": "就绪队列" 342 | "horizontalAlignment": 0 343 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 344 | "x": 0 345 | "y": 5 346 | "width": 85 347 | "height": 25 348 | } ) 349 | add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) { 350 | name: "scrollPane2" 351 | add( new FormComponent( "javax.swing.JTable" ) { 352 | name: "readyProcessTable" 353 | } ) 354 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 355 | "x": 10 356 | "y": 30 357 | "width": 690 358 | "height": 70 359 | } ) 360 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 361 | "x": 5 362 | "y": 390 363 | "height": 120 364 | "width": 715 365 | } ) 366 | add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class com.jformdesigner.runtime.NullLayout ) { 367 | "autoSize": false 368 | } ) { 369 | name: "panel8" 370 | "border": #EtchedBorder0 371 | add( new FormComponent( "javax.swing.JLabel" ) { 372 | name: "label15" 373 | "text": "阻塞队列" 374 | "horizontalAlignment": 0 375 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 376 | "x": 0 377 | "y": 0 378 | "width": 80 379 | "height": 30 380 | } ) 381 | add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) { 382 | name: "scrollPane3" 383 | add( new FormComponent( "javax.swing.JTable" ) { 384 | name: "blockProcessTable" 385 | } ) 386 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 387 | "x": 10 388 | "y": 30 389 | "width": 615 390 | "height": 70 391 | } ) 392 | add( new FormComponent( "javax.swing.JButton" ) { 393 | name: "wakeBtn" 394 | "text": "唤醒" 395 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 396 | "x": 635 397 | "y": 40 398 | "width": 68 399 | "height": 45 400 | } ) 401 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 402 | "width": 715 403 | "height": 105 404 | "x": 5 405 | "y": 510 406 | } ) 407 | add( new FormComponent( "javax.swing.JButton" ) { 408 | name: "resetBtn" 409 | "text": "重置" 410 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 411 | "x": 420 412 | "y": 635 413 | "width": 95 414 | "height": 40 415 | } ) 416 | add( new FormComponent( "javax.swing.JButton" ) { 417 | name: "exitBtn" 418 | "text": "退出" 419 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 420 | "width": 90 421 | "height": 40 422 | "x": 630 423 | "y": 635 424 | } ) 425 | add( new FormComponent( "javax.swing.JButton" ) { 426 | name: "pauseBtn" 427 | "text": "暂停" 428 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 429 | "x": 10 430 | "y": 635 431 | "width": 85 432 | "height": 40 433 | } ) 434 | add( new FormComponent( "javax.swing.JButton" ) { 435 | name: "continueBtn" 436 | "text": "继续" 437 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 438 | "width": 85 439 | "height": 40 440 | "x": 190 441 | "y": 635 442 | } ) 443 | }, new FormLayoutConstraints( null ) { 444 | "title": "进程创建" 445 | } ) 446 | add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class com.jformdesigner.runtime.NullLayout ) ) { 447 | name: "panel2" 448 | add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class com.jformdesigner.runtime.NullLayout ) { 449 | "autoSize": false 450 | } ) { 451 | name: "panel1" 452 | add( new FormComponent( "javax.swing.JLabel" ) { 453 | name: "label16" 454 | "text": "输入进程队列情况:" 455 | "font": new java.awt.Font( "方正舒体", 0, 18 ) 456 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 457 | "x": 0 458 | "y": 0 459 | "width": 165 460 | "height": 30 461 | } ) 462 | add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) { 463 | name: "scrollPane4" 464 | add( new FormComponent( "javax.swing.JTable" ) { 465 | name: "inputProcessTable" 466 | } ) 467 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 468 | "x": 5 469 | "y": 40 470 | "width": 720 471 | "height": 190 472 | } ) 473 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 474 | "x": 0 475 | "y": 0 476 | "height": 255 477 | "width": 730 478 | } ) 479 | add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class com.jformdesigner.runtime.NullLayout ) { 480 | "autoSize": false 481 | } ) { 482 | name: "panel9" 483 | add( new FormComponent( "javax.swing.JLabel" ) { 484 | name: "label17" 485 | "text": "执行后进程队列情况:" 486 | "font": new java.awt.Font( "方正舒体", 0, 18 ) 487 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 488 | "x": 5 489 | "y": 0 490 | "width": 190 491 | "height": 50 492 | } ) 493 | add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) { 494 | name: "scrollPane5" 495 | add( new FormComponent( "javax.swing.JTable" ) { 496 | name: "outputProcessTable" 497 | } ) 498 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 499 | "x": 0 500 | "y": 55 501 | "width": 720 502 | "height": 160 503 | } ) 504 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 505 | "width": 730 506 | "height": 240 507 | "x": 0 508 | "y": 255 509 | } ) 510 | add( new FormComponent( "javax.swing.JLabel" ) { 511 | name: "label21" 512 | "text": "平均带权周转时间:" 513 | "font": &Font1 new java.awt.Font( "方正舒体", 0, 22 ) 514 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 515 | "width": 210 516 | "height": 65 517 | "x": 5 518 | "y": 580 519 | } ) 520 | add( new FormComponent( "javax.swing.JLabel" ) { 521 | name: "avgWeightTurnTime" 522 | "text": "0" 523 | "font": #Font1 524 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 525 | "width": 140 526 | "height": 65 527 | "x": 250 528 | "y": 505 529 | } ) 530 | add( new FormComponent( "javax.swing.JLabel" ) { 531 | name: "avgTurnTime" 532 | "text": "0" 533 | "font": #Font1 534 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 535 | "x": 250 536 | "y": 580 537 | "width": 140 538 | "height": 65 539 | } ) 540 | add( new FormComponent( "javax.swing.JLabel" ) { 541 | name: "label20" 542 | "text": "平均周转时间:" 543 | "font": #Font1 544 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 545 | "x": 10 546 | "y": 505 547 | "width": 175 548 | "height": 65 549 | } ) 550 | }, new FormLayoutConstraints( null ) { 551 | "title": "结果预览" 552 | } ) 553 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 554 | "x": 0 555 | "y": 0 556 | "width": 730 557 | "height": 715 558 | } ) 559 | menuBar: new FormContainer( "javax.swing.JMenuBar", new FormLayoutManager( class javax.swing.JMenuBar ) ) { 560 | name: "menuBar1" 561 | "visible": false 562 | add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) { 563 | name: "menu1" 564 | "text": "文件" 565 | add( new FormComponent( "javax.swing.JMenuItem" ) { 566 | name: "loadMenuItem" 567 | "text": "导入" 568 | } ) 569 | } ) 570 | } 571 | }, new FormLayoutConstraints( null ) { 572 | "location": new java.awt.Point( 0, 0 ) 573 | "size": new java.awt.Dimension( 740, 780 ) 574 | } ) 575 | add( new FormNonVisual( "javax.swing.ButtonGroup" ) { 576 | name: "buttonGroup1" 577 | }, new FormLayoutConstraints( null ) { 578 | "location": new java.awt.Point( 0, 686 ) 579 | } ) 580 | } 581 | } 582 | -------------------------------------------------------------------------------- /src/main/view/mainFrame.jfd: -------------------------------------------------------------------------------- 1 | JFDML JFormDesigner: "6.0.2.0.116" Java: "1.8.0_181" encoding: "UTF-8" 2 | 3 | new FormModel { 4 | contentType: "form/swing" 5 | root: new FormRoot { 6 | add( new FormWindow( "javax.swing.JFrame", new FormLayoutManager( class com.jformdesigner.runtime.NullLayout ) ) { 7 | name: "this" 8 | add( new FormContainer( "javax.swing.JTabbedPane", new FormLayoutManager( class javax.swing.JTabbedPane ) ) { 9 | name: "mainTabbedPane" 10 | add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class com.jformdesigner.runtime.NullLayout ) ) { 11 | name: "createProcessPanel" 12 | add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class com.jformdesigner.runtime.NullLayout ) ) { 13 | name: "panel3" 14 | "border": new javax.swing.border.EtchedBorder( 1, null, null ) 15 | add( new FormComponent( "javax.swing.JButton" ) { 16 | name: "initialBtn" 17 | "text": "设置打印机" 18 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 19 | "x": 510 20 | "y": 5 21 | "width": 115 22 | "height": 45 23 | } ) 24 | add( new FormComponent( "javax.swing.JTextField" ) { 25 | name: "printerJFT" 26 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 27 | "x": 120 28 | "y": 20 29 | "width": 64 30 | "height": 30 31 | } ) 32 | add( new FormComponent( "javax.swing.JLabel" ) { 33 | name: "label1" 34 | "text": "初始设置" 35 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 36 | "x": 5 37 | "y": 0 38 | "width": 55 39 | "height": 25 40 | } ) 41 | add( new FormComponent( "javax.swing.JLabel" ) { 42 | name: "label3" 43 | "text": "打印机" 44 | "horizontalAlignment": 0 45 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 46 | "x": 50 47 | "y": 20 48 | "width": 66 49 | "height": 27 50 | } ) 51 | add( new FormComponent( "javax.swing.JLabel" ) { 52 | name: "label5" 53 | "text": "台" 54 | "horizontalAlignment": 0 55 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 56 | "x": 180 57 | "y": 20 58 | "width": 45 59 | "height": 27 60 | } ) 61 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 62 | "x": 5 63 | "y": 10 64 | "width": 715 65 | "height": 55 66 | } ) 67 | add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class com.jformdesigner.runtime.NullLayout ) { 68 | "autoSize": false 69 | } ) { 70 | name: "panel4" 71 | "border": &EtchedBorder0 new javax.swing.border.EtchedBorder( 1, null, null ) 72 | add( new FormComponent( "javax.swing.JLabel" ) { 73 | name: "label6" 74 | "text": "新建进程" 75 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 76 | "x": 5 77 | "y": 5 78 | "width": 60 79 | } ) 80 | add( new FormComponent( "javax.swing.JLabel" ) { 81 | name: "label7" 82 | "text": "进程名称 " 83 | "horizontalAlignment": 0 84 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 85 | "x": 45 86 | "y": 20 87 | "width": 70 88 | "height": 25 89 | } ) 90 | add( new FormComponent( "javax.swing.JLabel" ) { 91 | name: "label8" 92 | "text": "提交时间" 93 | "horizontalAlignment": 0 94 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 95 | "width": 70 96 | "height": 25 97 | "x": 130 98 | "y": 20 99 | } ) 100 | add( new FormComponent( "javax.swing.JLabel" ) { 101 | name: "label9" 102 | "text": "服务时间" 103 | "horizontalAlignment": 0 104 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 105 | "width": 70 106 | "height": 25 107 | "x": 195 108 | "y": 20 109 | } ) 110 | add( new FormComponent( "javax.swing.JLabel" ) { 111 | name: "label11" 112 | "text": "打印机请求数量" 113 | "horizontalAlignment": 0 114 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 115 | "width": 105 116 | "height": 25 117 | "x": 345 118 | "y": 20 119 | } ) 120 | add( new FormComponent( "javax.swing.JTextField" ) { 121 | name: "processNameJFT" 122 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 123 | "x": 45 124 | "y": 50 125 | "height": 25 126 | "width": 69 127 | } ) 128 | add( new FormComponent( "javax.swing.JTextField" ) { 129 | name: "submitTimeJFT" 130 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 131 | "width": 64 132 | "height": 25 133 | "x": 130 134 | "y": 50 135 | } ) 136 | add( new FormComponent( "javax.swing.JTextField" ) { 137 | name: "serveTimeJFT" 138 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 139 | "width": 64 140 | "height": 25 141 | "x": 200 142 | "y": 50 143 | } ) 144 | add( new FormComponent( "javax.swing.JTextField" ) { 145 | name: "printerReqJFT" 146 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 147 | "width": 64 148 | "height": 25 149 | "x": 365 150 | "y": 50 151 | } ) 152 | add( new FormComponent( "javax.swing.JButton" ) { 153 | name: "newProcessBtn" 154 | "text": "新建进程" 155 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 156 | "x": 480 157 | "y": 20 158 | "width": 100 159 | "height": 45 160 | } ) 161 | add( new FormComponent( "javax.swing.JLabel" ) { 162 | name: "label18" 163 | "text": "优先级" 164 | "horizontalAlignment": 0 165 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 166 | "x": 275 167 | "y": 25 168 | "width": 50 169 | } ) 170 | add( new FormComponent( "javax.swing.JTextField" ) { 171 | name: "priorityJFT" 172 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 173 | "x": 275 174 | "y": 50 175 | "width": 64 176 | "height": 25 177 | } ) 178 | add( new FormComponent( "javax.swing.JButton" ) { 179 | name: "LoadFileBtn" 180 | "text": "导入文件" 181 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 182 | "width": 100 183 | "height": 45 184 | "x": 595 185 | "y": 20 186 | } ) 187 | add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) { 188 | name: "scrollPane6" 189 | add( new FormComponent( "javax.swing.JTable" ) { 190 | name: "createProcessTable" 191 | } ) 192 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 193 | "x": 15 194 | "y": 80 195 | "width": 680 196 | "height": 95 197 | } ) 198 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 199 | "x": 5 200 | "y": 60 201 | "height": 180 202 | "width": 715 203 | } ) 204 | add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class com.jformdesigner.runtime.NullLayout ) { 205 | "autoSize": false 206 | } ) { 207 | name: "panel5" 208 | "border": #EtchedBorder0 209 | add( new FormComponent( "javax.swing.JLabel" ) { 210 | name: "label12" 211 | "text": "请选择模拟方法:" 212 | "horizontalAlignment": 0 213 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 214 | "x": 15 215 | "y": 15 216 | "width": 125 217 | "height": 25 218 | } ) 219 | add( new FormComponent( "javax.swing.JRadioButton" ) { 220 | name: "noGrabRadioBtn" 221 | "text": "非抢占式优先调度" 222 | "$buttonGroup": new FormReference( "buttonGroup1" ) 223 | "selected": true 224 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 225 | "x": 165 226 | "y": 15 227 | "width": 140 228 | } ) 229 | add( new FormComponent( "javax.swing.JRadioButton" ) { 230 | name: "grabRadioBtnButton2" 231 | "text": "抢占式优先调度" 232 | "$buttonGroup": new FormReference( "buttonGroup1" ) 233 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 234 | "width": 140 235 | "height": 19 236 | "x": 340 237 | "y": 20 238 | } ) 239 | add( new FormComponent( "javax.swing.JButton" ) { 240 | name: "startBtn" 241 | "text": "开始模拟" 242 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 243 | "x": 530 244 | "y": 10 245 | "width": 110 246 | "height": 35 247 | } ) 248 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 249 | "x": 5 250 | "y": 240 251 | "height": 50 252 | "width": 715 253 | } ) 254 | add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class com.jformdesigner.runtime.NullLayout ) { 255 | "autoSize": false 256 | } ) { 257 | name: "panel6" 258 | "border": #EtchedBorder0 259 | add( new FormComponent( "javax.swing.JLabel" ) { 260 | name: "label13" 261 | "text": "运行进程队列" 262 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 263 | "x": 5 264 | "y": 5 265 | "width": 120 266 | "height": 25 267 | } ) 268 | add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) { 269 | name: "scrollPane1" 270 | add( new FormComponent( "javax.swing.JTable" ) { 271 | name: "currentProcessTable" 272 | } ) 273 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 274 | "x": 15 275 | "y": 40 276 | "width": 605 277 | "height": 40 278 | } ) 279 | add( new FormComponent( "javax.swing.JLabel" ) { 280 | name: "label19" 281 | "text": "当前时间:" 282 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 283 | "x": 150 284 | "y": 10 285 | "width": 75 286 | } ) 287 | add( new FormComponent( "javax.swing.JLabel" ) { 288 | name: "currentTimeJFT" 289 | "horizontalAlignment": 2 290 | "text": "0" 291 | "font": &Font0 new java.awt.Font( "Microsoft YaHei UI", 0, 13 ) 292 | "verticalAlignment": 1 293 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 294 | "x": 220 295 | "y": 10 296 | "width": 50 297 | "height": 20 298 | } ) 299 | add( new FormComponent( "javax.swing.JLabel" ) { 300 | name: "label24" 301 | "text": "当前剩余打印机数:" 302 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 303 | "x": 295 304 | "y": 10 305 | "width": 125 306 | } ) 307 | add( new FormComponent( "javax.swing.JLabel" ) { 308 | name: "currentPrinterJFT" 309 | "text": "0" 310 | "horizontalAlignment": 2 311 | "verticalAlignment": 1 312 | "font": #Font0 313 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 314 | "x": 415 315 | "y": 10 316 | "width": 50 317 | "height": 20 318 | } ) 319 | add( new FormComponent( "javax.swing.JButton" ) { 320 | name: "blockBtn" 321 | "text": "阻塞" 322 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 323 | "x": 630 324 | "y": 30 325 | "width": 75 326 | "height": 50 327 | } ) 328 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 329 | "x": 5 330 | "y": 285 331 | "height": 110 332 | "width": 715 333 | } ) 334 | add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class com.jformdesigner.runtime.NullLayout ) { 335 | "autoSize": false 336 | } ) { 337 | name: "panel7" 338 | "border": #EtchedBorder0 339 | add( new FormComponent( "javax.swing.JLabel" ) { 340 | name: "label14" 341 | "text": "就绪队列" 342 | "horizontalAlignment": 0 343 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 344 | "x": 0 345 | "y": 5 346 | "width": 85 347 | "height": 25 348 | } ) 349 | add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) { 350 | name: "scrollPane2" 351 | add( new FormComponent( "javax.swing.JTable" ) { 352 | name: "readyProcessTable" 353 | } ) 354 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 355 | "x": 10 356 | "y": 30 357 | "width": 690 358 | "height": 70 359 | } ) 360 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 361 | "x": 5 362 | "y": 390 363 | "height": 120 364 | "width": 715 365 | } ) 366 | add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class com.jformdesigner.runtime.NullLayout ) { 367 | "autoSize": false 368 | } ) { 369 | name: "panel8" 370 | "border": #EtchedBorder0 371 | add( new FormComponent( "javax.swing.JLabel" ) { 372 | name: "label15" 373 | "text": "阻塞队列" 374 | "horizontalAlignment": 0 375 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 376 | "x": 0 377 | "y": 0 378 | "width": 80 379 | "height": 30 380 | } ) 381 | add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) { 382 | name: "scrollPane3" 383 | add( new FormComponent( "javax.swing.JTable" ) { 384 | name: "blockProcessTable" 385 | } ) 386 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 387 | "x": 10 388 | "y": 30 389 | "width": 615 390 | "height": 70 391 | } ) 392 | add( new FormComponent( "javax.swing.JButton" ) { 393 | name: "wakeBtn" 394 | "text": "唤醒" 395 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 396 | "x": 635 397 | "y": 40 398 | "width": 68 399 | "height": 45 400 | } ) 401 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 402 | "width": 715 403 | "height": 105 404 | "x": 5 405 | "y": 510 406 | } ) 407 | add( new FormComponent( "javax.swing.JButton" ) { 408 | name: "resetBtn" 409 | "text": "重置" 410 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 411 | "x": 420 412 | "y": 635 413 | "width": 95 414 | "height": 40 415 | } ) 416 | add( new FormComponent( "javax.swing.JButton" ) { 417 | name: "exitBtn" 418 | "text": "退出" 419 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 420 | "width": 90 421 | "height": 40 422 | "x": 630 423 | "y": 635 424 | } ) 425 | add( new FormComponent( "javax.swing.JButton" ) { 426 | name: "pauseBtn" 427 | "text": "暂停" 428 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 429 | "x": 10 430 | "y": 635 431 | "width": 85 432 | "height": 40 433 | } ) 434 | add( new FormComponent( "javax.swing.JButton" ) { 435 | name: "continueBtn" 436 | "text": "继续" 437 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 438 | "width": 85 439 | "height": 40 440 | "x": 190 441 | "y": 635 442 | } ) 443 | }, new FormLayoutConstraints( null ) { 444 | "title": "进程创建" 445 | } ) 446 | add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class com.jformdesigner.runtime.NullLayout ) ) { 447 | name: "panel2" 448 | add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class com.jformdesigner.runtime.NullLayout ) { 449 | "autoSize": false 450 | } ) { 451 | name: "panel1" 452 | add( new FormComponent( "javax.swing.JLabel" ) { 453 | name: "label16" 454 | "text": "输入进程队列情况:" 455 | "font": new java.awt.Font( "方正舒体", 0, 18 ) 456 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 457 | "x": 0 458 | "y": 0 459 | "width": 165 460 | "height": 30 461 | } ) 462 | add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) { 463 | name: "scrollPane4" 464 | add( new FormComponent( "javax.swing.JTable" ) { 465 | name: "inputProcessTable" 466 | } ) 467 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 468 | "x": 5 469 | "y": 40 470 | "width": 720 471 | "height": 190 472 | } ) 473 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 474 | "x": 0 475 | "y": 0 476 | "height": 255 477 | "width": 730 478 | } ) 479 | add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class com.jformdesigner.runtime.NullLayout ) { 480 | "autoSize": false 481 | } ) { 482 | name: "panel9" 483 | add( new FormComponent( "javax.swing.JLabel" ) { 484 | name: "label17" 485 | "text": "执行后进程队列情况:" 486 | "font": new java.awt.Font( "方正舒体", 0, 18 ) 487 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 488 | "x": 5 489 | "y": 0 490 | "width": 190 491 | "height": 50 492 | } ) 493 | add( new FormContainer( "javax.swing.JScrollPane", new FormLayoutManager( class javax.swing.JScrollPane ) ) { 494 | name: "scrollPane5" 495 | add( new FormComponent( "javax.swing.JTable" ) { 496 | name: "outputProcessTable" 497 | } ) 498 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 499 | "x": 0 500 | "y": 55 501 | "width": 720 502 | "height": 160 503 | } ) 504 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 505 | "width": 730 506 | "height": 240 507 | "x": 0 508 | "y": 255 509 | } ) 510 | add( new FormComponent( "javax.swing.JLabel" ) { 511 | name: "label21" 512 | "text": "平均带权周转时间:" 513 | "font": &Font1 new java.awt.Font( "方正舒体", 0, 22 ) 514 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 515 | "width": 210 516 | "height": 65 517 | "x": 5 518 | "y": 580 519 | } ) 520 | add( new FormComponent( "javax.swing.JLabel" ) { 521 | name: "avgWeightTurnTime" 522 | "text": "0" 523 | "font": #Font1 524 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 525 | "width": 140 526 | "height": 65 527 | "x": 250 528 | "y": 505 529 | } ) 530 | add( new FormComponent( "javax.swing.JLabel" ) { 531 | name: "avgTurnTime" 532 | "text": "0" 533 | "font": #Font1 534 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 535 | "x": 250 536 | "y": 580 537 | "width": 140 538 | "height": 65 539 | } ) 540 | add( new FormComponent( "javax.swing.JLabel" ) { 541 | name: "label20" 542 | "text": "平均周转时间:" 543 | "font": #Font1 544 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 545 | "x": 10 546 | "y": 505 547 | "width": 175 548 | "height": 65 549 | } ) 550 | }, new FormLayoutConstraints( null ) { 551 | "title": "结果预览" 552 | } ) 553 | }, new FormLayoutConstraints( class com.jformdesigner.runtime.NullConstraints ) { 554 | "x": 0 555 | "y": 0 556 | "width": 730 557 | "height": 715 558 | } ) 559 | menuBar: new FormContainer( "javax.swing.JMenuBar", new FormLayoutManager( class javax.swing.JMenuBar ) ) { 560 | name: "menuBar1" 561 | "visible": false 562 | add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) { 563 | name: "menu1" 564 | "text": "文件" 565 | add( new FormComponent( "javax.swing.JMenuItem" ) { 566 | name: "loadMenuItem" 567 | "text": "导入" 568 | } ) 569 | } ) 570 | } 571 | }, new FormLayoutConstraints( null ) { 572 | "location": new java.awt.Point( 0, 0 ) 573 | "size": new java.awt.Dimension( 740, 780 ) 574 | } ) 575 | add( new FormNonVisual( "javax.swing.ButtonGroup" ) { 576 | name: "buttonGroup1" 577 | }, new FormLayoutConstraints( null ) { 578 | "location": new java.awt.Point( 0, 686 ) 579 | } ) 580 | } 581 | } 582 | -------------------------------------------------------------------------------- /src/main/controller/MainFrameController.java: -------------------------------------------------------------------------------- 1 | package main.controller; 2 | 3 | import main.model.BlockProcessTableModel; 4 | import main.model.CurProcessTableModel; 5 | import main.model.InputProcessTableModel; 6 | import main.model.OutputProcessTableModel; 7 | import main.model.ReadyProcessTableModel; 8 | import main.process.ProcessData; 9 | import main.utils.ProcessSort; 10 | import main.utils.ProcessStatus; 11 | import main.view.MainFrame; 12 | 13 | import javax.swing.*; 14 | import javax.swing.event.ChangeEvent; 15 | import javax.swing.event.ChangeListener; 16 | import javax.swing.filechooser.FileNameExtensionFilter; 17 | import javax.swing.table.DefaultTableCellRenderer; 18 | import javax.swing.table.TableModel; 19 | import java.awt.*; 20 | import java.awt.event.ActionEvent; 21 | import java.awt.event.ActionListener; 22 | import java.io.BufferedReader; 23 | import java.io.File; 24 | import java.io.FileNotFoundException; 25 | import java.io.FileReader; 26 | import java.io.IOException; 27 | import java.util.ArrayList; 28 | import java.util.List; 29 | 30 | /** 31 | * @Auther: Administrator 32 | * @Date: 2018/11/2 13:42 33 | * @Description: 34 | */ 35 | public class MainFrameController { 36 | private MainFrame mainFrame; 37 | private JTabbedPane mainTabbedPane; 38 | private JButton initialBtn; 39 | private JTextField printerJFT; 40 | private JTextField processNameJFT; 41 | private JTextField arriveTimeJFT; 42 | private JTextField serveTimeJFT; 43 | private JTextField printerReqJFT; 44 | private JTextField priorityJFT; 45 | private JLabel currentTimeJFT; 46 | private JButton newProcessBtn; 47 | private JButton loadFileBtn; 48 | private JRadioButton selectGrab; 49 | private JRadioButton selectNoGrab; 50 | private JButton startBtn; 51 | private JTable currentProcessTable; 52 | private JButton blockBtn; 53 | private JButton pauseBtn; 54 | private JButton continueBtn; 55 | private JButton wakeBtn; 56 | private JButton resetBtn; 57 | private JButton exitBtn; 58 | private JTable readyProcessTable; 59 | private JTable blockProcessTable; 60 | private JTable inputProcessTable; 61 | private JTable outputProcessTable; 62 | private JTable createProcessTable; 63 | private JMenuItem loadMenuItem; 64 | private JLabel avgTurnTime; 65 | private JLabel avgWeightTurnTime; 66 | private JLabel currentMemoryJFT; 67 | private JLabel currentPrinterJFT; 68 | 69 | // 定义model 70 | private CurProcessTableModel curProcessTableModel = new CurProcessTableModel(); 71 | private ReadyProcessTableModel readyProcessTableModel = new ReadyProcessTableModel(); 72 | private BlockProcessTableModel blockProcessTableModel = new BlockProcessTableModel(); 73 | private InputProcessTableModel inputProcessTableModel = new InputProcessTableModel(); 74 | private OutputProcessTableModel outputProcessTableModel = new OutputProcessTableModel(); 75 | 76 | // 当前时间 77 | volatile private int currentTime=0; 78 | // 就绪队列 79 | private List readyProcessQueue = new ArrayList<>(); 80 | // 阻塞队列 81 | private List blockProcessQueue = new ArrayList<>(); 82 | // 创建进程暂存队列 83 | private List tempProcessQueue = new ArrayList<>(); 84 | // 记录已完成进程 85 | private List finishProcessList = new ArrayList<>(); 86 | 87 | // 当前执行进程 88 | private ProcessData currentProcess = null; 89 | // 打印机数目 90 | private int totalPrinterNum = 0; 91 | private int curPrinterNum = 0; 92 | // 时钟 93 | private Timer timer; 94 | 95 | public MainFrameController() { 96 | mainFrame = new MainFrame(); 97 | initCompoents(); 98 | initListeners(); 99 | 100 | // 定义时钟 101 | timer = new Timer(1000, new ActionListener() { 102 | 103 | @Override 104 | public void actionPerformed(ActionEvent e) { 105 | // 当前进程剩余执行时间减一 106 | if (currentProcess != null) 107 | { 108 | currentProcess.subMoreTime(); 109 | } 110 | // 暂时记录因资源不足暂时无法创建的进程 111 | List processDataList = new ArrayList<>(); 112 | // 处理到达的进程 113 | while (tempProcessQueue.size() > 0) { 114 | if (tempProcessQueue.get(0).getArriveTime() <= currentTime) { 115 | // 首先为到达进程分配资源,如资源不够则继续等待 116 | if (curPrinterNum >= tempProcessQueue.get(0).getPrinterReq()) { 117 | curPrinterNum -= tempProcessQueue.get(0).getPrinterReq(); 118 | if (selectNoGrab.isSelected()) { 119 | // 非抢占式优先级调度 120 | ProcessData process = tempProcessQueue.remove(0); 121 | noGrabDispatch(process); 122 | } else if (selectGrab.isSelected()) { 123 | // 抢占式优先级调度 124 | ProcessData process = tempProcessQueue.remove(0); 125 | grabDispatch(process); 126 | } 127 | } else { 128 | processDataList.add(tempProcessQueue.remove(0)); 129 | } 130 | } else break; 131 | } 132 | // 处理队列中元素 133 | while (!processDataList.isEmpty()) { 134 | tempProcessQueue.add(processDataList.remove(0)); 135 | } 136 | // 重新按到达时间排序 137 | ProcessSort.sortByArriveTime(tempProcessQueue); 138 | 139 | // 当前cpu空闲直接取就绪队列队首进程 140 | if (currentProcess == null) { 141 | if (readyProcessQueue.size() > 0) { 142 | dispatchQueueFirst(); 143 | } 144 | } else { 145 | // 进程执行完毕 146 | if (currentProcess.isFinished()) { 147 | // 将状态置为完成 148 | currentProcess.setStatus(ProcessStatus.FINISH); 149 | // 设置完成时间 150 | currentProcess.setFinishTime(currentTime); 151 | 152 | // 记录已完成进程 153 | finishProcessList.add(currentProcess); 154 | // 归还资源 155 | curPrinterNum += currentProcess.getPrinterReq(); 156 | 157 | currentProcess = null; 158 | // 有进程执行完毕 引发进程调度 159 | while (tempProcessQueue.size() > 0) { 160 | if (tempProcessQueue.get(0).getArriveTime() <= currentTime) { 161 | // 首先为到达进程分配资源,如资源不够则继续等待 162 | if ( curPrinterNum >= tempProcessQueue.get(0).getPrinterReq()) { 163 | curPrinterNum -= tempProcessQueue.get(0).getPrinterReq(); 164 | if (selectNoGrab.isSelected()) { 165 | // 非抢占式优先级调度 166 | ProcessData process = tempProcessQueue.remove(0); 167 | noGrabDispatch(process); 168 | } else if (selectGrab.isSelected()) { 169 | // 抢占式优先级调度 170 | ProcessData process = tempProcessQueue.remove(0); 171 | grabDispatch(process); 172 | } 173 | } else break; 174 | } else break; 175 | } 176 | 177 | if (readyProcessQueue.size() > 0) { 178 | dispatchQueueFirst(); 179 | } 180 | } 181 | } 182 | 183 | 184 | currentPrinterJFT.setText(String.valueOf(curPrinterNum)); 185 | 186 | // 更新界面当前时间 187 | currentTimeJFT.setText(String.valueOf(currentTime)); 188 | // 更新table 189 | readyProcessTableModel.setProcessQueue(readyProcessQueue); 190 | curProcessTableModel.setCurrentProcess(currentProcess); 191 | currentProcessTable.updateUI(); 192 | readyProcessTable.updateUI(); 193 | 194 | // 判断执行完毕 195 | if (readyProcessQueue.size() == 0 && blockProcessQueue.size() == 0 && currentProcess == null && tempProcessQueue.size() == 0) { 196 | JOptionPane.showMessageDialog(null, "所有进程已执行完毕!"); 197 | timer.stop(); 198 | return; 199 | } 200 | 201 | // 定时器加1 202 | currentTime += 1; 203 | } 204 | }); 205 | } 206 | 207 | /** 208 | * 调度就绪队列队首进程 209 | * 210 | * @param 211 | */ 212 | private void dispatchQueueFirst() { 213 | if (readyProcessQueue.size() > 0) { 214 | currentProcess = readyProcessQueue.remove(0); 215 | // 将状态置为执行 216 | currentProcess.setStatus(ProcessStatus.RUNNING); 217 | // 记录开始执行时间 218 | if (currentProcess.getBeginTime() == -1) 219 | currentProcess.setBeginTime(currentTime-1); 220 | 221 | } 222 | } 223 | 224 | /** 225 | * 非抢占式优先级进程调度 226 | * 227 | * @param process 228 | */ 229 | private void noGrabDispatch(ProcessData process) { 230 | // 置为就绪状态 231 | process.setStatus(ProcessStatus.READY); 232 | readyProcessQueue.add(process); 233 | ProcessSort.sortByPriority(readyProcessQueue); 234 | 235 | } 236 | 237 | /** 238 | * 抢占式优先级进程调度 239 | * 240 | * @param process 241 | */ 242 | private void grabDispatch(ProcessData process) { 243 | // 比较与现行进程优先级关系 244 | if (currentProcess != null) { 245 | // 优先级高于现行进程 246 | if (process.getPrio() > currentProcess.getPrio()) { 247 | // 现行进程 -》 就绪队列 248 | if (currentProcess.isFinished()) { 249 | // 将状态置为完成 250 | currentProcess.setStatus(ProcessStatus.FINISH); 251 | // 设置完成时间 252 | currentProcess.setFinishTime(currentTime); 253 | // 记录已完成进程 254 | finishProcessList.add(currentProcess); 255 | // 归还资源 256 | curPrinterNum += currentProcess.getPrinterReq(); 257 | 258 | currentProcess = null; 259 | } 260 | else 261 | { 262 | currentProcess.setStatus(ProcessStatus.READY); 263 | readyProcessQueue.add(currentProcess); 264 | } 265 | ProcessSort.sortByPriority(readyProcessQueue); 266 | // 该进程 抢占cpu 267 | currentProcess = process; 268 | // 记录开始时间 269 | if (currentProcess.getBeginTime() == -1) { 270 | currentProcess.setBeginTime(currentTime); 271 | } 272 | // 置为执行状态 273 | currentProcess.setStatus(ProcessStatus.RUNNING); 274 | } else { 275 | // 优先级低于现行进程 276 | // -》 就绪队列 277 | // 置为就绪状态 278 | process.setStatus(ProcessStatus.READY); 279 | readyProcessQueue.add(process); 280 | ProcessSort.sortByPriority(readyProcessQueue); 281 | } 282 | } else { 283 | currentProcess = process; 284 | currentProcess.setStatus(ProcessStatus.RUNNING); 285 | // 记录开始执行时间 286 | if (currentProcess.getBeginTime() == -1) 287 | currentProcess.setBeginTime(currentTime); 288 | } 289 | } 290 | 291 | private void initListeners() { 292 | // 创建进程 293 | newProcessBtn.addActionListener(new ActionListener() { 294 | @Override 295 | public void actionPerformed(ActionEvent e) { 296 | // 判断输入是否为空 297 | if ("".equals(processNameJFT.getText()) || "".equals(arriveTimeJFT.getText()) || 298 | "".equals(serveTimeJFT.getText()) || "".equals(printerJFT.getText()) || "".equals(printerJFT.getText())) { 299 | JOptionPane.showMessageDialog(null, "输入不能为空"); 300 | return; 301 | } 302 | String processName = processNameJFT.getText(); 303 | int arrive_time = Integer.parseInt(arriveTimeJFT.getText()); 304 | int serve_time = Integer.parseInt(serveTimeJFT.getText()); 305 | int priority = Integer.parseInt(priorityJFT.getText()); 306 | int printerReq = Integer.parseInt(printerReqJFT.getText()); 307 | 308 | if (printerReq > totalPrinterNum) { 309 | JOptionPane.showMessageDialog(null, "当前请求打印机数大于系统打印机资源数,创建进程失败!"); 310 | return; 311 | } else if (arrive_time < currentTime) { 312 | JOptionPane.showMessageDialog(null, "到达时间需大于等于当前时间,创建进程失败!"); 313 | return; 314 | } 315 | 316 | // 创建进程对象 317 | ProcessData processData = new ProcessData(processName, arrive_time, serve_time, priority,printerReq); 318 | tempProcessQueue.add(processData); 319 | // 到达时间排序 320 | ProcessSort.sortByArriveTime(tempProcessQueue); 321 | // 添加到输入table 322 | inputProcessTableModel.addProcess(processData); 323 | createProcessTable.updateUI(); 324 | // 创建成功 325 | JOptionPane.showMessageDialog(null, "创建进程成功!"); 326 | processNameJFT.setText(""); 327 | arriveTimeJFT.setText(""); 328 | serveTimeJFT.setText(""); 329 | printerReqJFT.setText(""); 330 | priorityJFT.setText(""); 331 | currentPrinterJFT.setText(String.valueOf(curPrinterNum)); 332 | } 333 | }); 334 | 335 | // 初始化内存与打印机 336 | initialBtn.addActionListener(new ActionListener() { 337 | @Override 338 | public void actionPerformed(ActionEvent e) { 339 | totalPrinterNum = curPrinterNum = Integer.parseInt(printerJFT.getText()); 340 | currentPrinterJFT.setText(String.valueOf(curPrinterNum)); 341 | JOptionPane.showMessageDialog(null, "打印机设置成功"); 342 | } 343 | }); 344 | 345 | // 开始模拟 346 | startBtn.addActionListener(new ActionListener() { 347 | @Override 348 | public void actionPerformed(ActionEvent e) { 349 | timer.start(); 350 | } 351 | }); 352 | 353 | // 暂停 354 | pauseBtn.addActionListener(new ActionListener() { 355 | @Override 356 | public void actionPerformed(ActionEvent e) { 357 | timer.stop(); 358 | } 359 | }); 360 | // 继续 361 | continueBtn.addActionListener(new ActionListener() { 362 | @Override 363 | public void actionPerformed(ActionEvent e) { 364 | timer.restart(); 365 | } 366 | }); 367 | 368 | // 阻塞 369 | blockBtn.addActionListener(new ActionListener() { 370 | @Override 371 | public void actionPerformed(ActionEvent e) { 372 | if (currentProcess != null) { 373 | // 将状态置为阻塞 374 | currentProcess.setStatus(ProcessStatus.BLOCKED); 375 | blockProcessQueue.add(currentProcess); 376 | blockProcessTableModel.setProcessQueue(blockProcessQueue); 377 | blockProcessTable.updateUI(); 378 | currentProcess = null; 379 | // 阻塞后当前进程为空 -- 可能引发进程调度 380 | dispatchQueueFirst(); 381 | curProcessTableModel.setCurrentProcess(currentProcess); 382 | currentProcessTable.updateUI(); 383 | blockProcessTable.updateUI(); 384 | } 385 | } 386 | }); 387 | wakeBtn.addActionListener(new ActionListener() { 388 | @Override 389 | public void actionPerformed(ActionEvent e) { 390 | // 获取阻塞队列队首进程 391 | if (!blockProcessQueue.isEmpty()) { 392 | ProcessData process = blockProcessQueue.remove(0); 393 | if (selectNoGrab.isSelected()) { 394 | // 非抢占式优先级调度 395 | noGrabDispatch(process); 396 | } else if (selectGrab.isSelected()) { 397 | // 抢占式优先级 398 | grabDispatch(process); 399 | } 400 | // 重绘 401 | blockProcessTableModel.setProcessQueue(blockProcessQueue); 402 | blockProcessTable.updateUI(); 403 | readyProcessTable.updateUI(); 404 | currentProcessTable.updateUI(); 405 | } 406 | } 407 | }); 408 | 409 | // 重置按钮 410 | resetBtn.addActionListener(new ActionListener() { 411 | @Override 412 | public void actionPerformed(ActionEvent e) { 413 | currentTime = 0; 414 | readyProcessQueue.clear(); 415 | blockProcessQueue.clear(); 416 | tempProcessQueue.clear(); 417 | finishProcessList.clear(); 418 | currentProcess = null; 419 | totalPrinterNum = 0; 420 | curPrinterNum = 0; 421 | 422 | printerJFT.setText(""); 423 | processNameJFT.setText(""); 424 | arriveTimeJFT.setText(""); 425 | serveTimeJFT.setText(""); 426 | printerReqJFT.setText(""); 427 | priorityJFT.setText(""); 428 | currentTimeJFT.setText("0"); 429 | 430 | curProcessTableModel.setCurrentProcess(currentProcess); 431 | readyProcessTableModel.setProcessQueue(readyProcessQueue); 432 | blockProcessTableModel.setProcessQueue(blockProcessQueue); 433 | inputProcessTableModel.clearProcess(); 434 | outputProcessTableModel.setProcessQueue(finishProcessList); 435 | 436 | currentPrinterJFT.setText(String.valueOf(curPrinterNum)); 437 | 438 | mainFrame.validate(); 439 | mainFrame.repaint(); 440 | 441 | // 停止定时器 442 | timer.stop(); 443 | 444 | } 445 | }); 446 | // 选项卡切换监听事件 447 | mainTabbedPane.addChangeListener(new ChangeListener() { 448 | @Override 449 | public void stateChanged(ChangeEvent e) { 450 | JTabbedPane tabbedPane = (JTabbedPane) e.getSource(); 451 | int selectedIndex = tabbedPane.getSelectedIndex(); 452 | // 选择结果panel 453 | if (selectedIndex == 1) { 454 | outputProcessTableModel.setProcessQueue(finishProcessList); 455 | // 重绘 456 | inputProcessTable.updateUI(); 457 | outputProcessTable.updateUI(); 458 | createProcessTable.updateUI(); 459 | // 周转时间 460 | double tunrTime = 0; 461 | // 带权周转时间 462 | double weightTurnTime = 0; 463 | for (ProcessData p : finishProcessList) { 464 | tunrTime += p.getFinishTime() - p.getArriveTime(); 465 | weightTurnTime += (p.getFinishTime() - p.getArriveTime()) * 1.0 / p.getNeedTime(); 466 | } 467 | if (finishProcessList.size() > 0) { 468 | tunrTime /= finishProcessList.size(); 469 | weightTurnTime /= finishProcessList.size(); 470 | } 471 | 472 | avgTurnTime.setText(String.valueOf(Math.round(tunrTime * 100) / 100.0)); 473 | avgWeightTurnTime.setText(String.valueOf(Math.round(weightTurnTime * 100) / 100.0)); 474 | } 475 | } 476 | }); 477 | loadFileBtn.addActionListener(new ActionListener() { 478 | @Override 479 | public void actionPerformed(ActionEvent e) { 480 | 481 | JFileChooser fileChooser = new JFileChooser(); 482 | fileChooser.setCurrentDirectory(new File("./src/testFile")); 483 | fileChooser.setDialogTitle("打开"); 484 | 485 | FileNameExtensionFilter filter = new FileNameExtensionFilter("Text Files ", "txt"); 486 | fileChooser.setFileFilter(filter); 487 | fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); 488 | fileChooser.setAcceptAllFileFilterUsed(false); 489 | 490 | if (fileChooser.showSaveDialog(mainFrame) == JFileChooser.APPROVE_OPTION) { 491 | File path = fileChooser.getSelectedFile(); 492 | BufferedReader bufferedReader = null; 493 | try { 494 | bufferedReader = new BufferedReader(new FileReader(path)); 495 | String tempString; 496 | while ((tempString = bufferedReader.readLine()) != null) { 497 | String[] processMsg = tempString.split(" "); 498 | // 创建进程对象 499 | ProcessData processData = new ProcessData(processMsg[0], Integer.parseInt(processMsg[1]), 500 | Integer.parseInt(processMsg[2]), Integer.parseInt(processMsg[3]), Integer.parseInt(processMsg[4])); 501 | 502 | if (processData.getPrinterReq() > totalPrinterNum) { 503 | JOptionPane.showMessageDialog(null, "进程 " + processData.getName() + "创建失败,因请求打印机数大于系统打印机资源数"); 504 | continue; 505 | } 506 | // 添加至临时队列 507 | tempProcessQueue.add(processData); 508 | // 到达时间排序 509 | ProcessSort.sortByArriveTime(tempProcessQueue); 510 | // 添加到输入table 511 | inputProcessTableModel.addProcess(processData); 512 | createProcessTable.updateUI(); 513 | currentPrinterJFT.setText(String.valueOf(curPrinterNum)); 514 | 515 | } 516 | } catch (FileNotFoundException e1) { 517 | e1.printStackTrace(); 518 | } catch (IOException e1) { 519 | e1.printStackTrace(); 520 | } 521 | 522 | } 523 | 524 | } 525 | }); 526 | 527 | exitBtn.addActionListener(new ActionListener() { 528 | @Override 529 | public void actionPerformed(ActionEvent e) { 530 | mainFrame.dispose(); 531 | System.exit(0); 532 | } 533 | }); 534 | } 535 | 536 | private void initCompoents() { 537 | mainTabbedPane = mainFrame.getMainTabbedPane(); 538 | initialBtn = mainFrame.getInitialBtn(); 539 | printerJFT = mainFrame.getPrinterJFT(); 540 | processNameJFT = mainFrame.getProcessNameJFT(); 541 | arriveTimeJFT = mainFrame.getSubmitTimeJFT(); 542 | serveTimeJFT = mainFrame.getServeTimeJFT(); 543 | printerReqJFT = mainFrame.getPrinterReqJFT(); 544 | newProcessBtn = mainFrame.getNewProcessBtn(); 545 | loadFileBtn=mainFrame.getLoadFileBtn(); 546 | selectGrab = mainFrame.getGrabRadioBtnButton2(); 547 | selectNoGrab = mainFrame.getNoGrabRadioBtn(); 548 | startBtn = mainFrame.getStartBtn(); 549 | currentProcessTable = mainFrame.getCurrentProcessTable(); 550 | createProcessTable=mainFrame.getCreateProcessTable(); 551 | blockBtn = mainFrame.getBlockBtn(); 552 | pauseBtn = mainFrame.getPauseBtn(); 553 | continueBtn = mainFrame.getContinueBtn(); 554 | readyProcessTable = mainFrame.getReadyProcessTable(); 555 | blockProcessTable = mainFrame.getBlockProcessTable(); 556 | wakeBtn = mainFrame.getWakeBtn(); 557 | resetBtn = mainFrame.getResetBtn(); 558 | exitBtn = mainFrame.getExitBtn(); 559 | priorityJFT = mainFrame.getPriorityJFT(); 560 | currentTimeJFT = mainFrame.getCurrentTimeJFT(); 561 | inputProcessTable = mainFrame.getInputProcessTable(); 562 | outputProcessTable = mainFrame.getOutputProcessTable(); 563 | loadMenuItem = mainFrame.getLoadMenuItem(); 564 | avgTurnTime = mainFrame.getAvgTurnTime(); 565 | avgWeightTurnTime = mainFrame.getAvgWeightTurnTime(); 566 | currentPrinterJFT = mainFrame.getCurrentPrinterJFT(); 567 | 568 | // 设置 当前进程 model 569 | setTableModel(currentProcessTable, curProcessTableModel); 570 | 571 | // 设置就绪队列 table model 572 | setTableModel(readyProcessTable, readyProcessTableModel); 573 | 574 | // 设置阻塞队列 table model 575 | setTableModel(blockProcessTable, blockProcessTableModel); 576 | 577 | // 设置输入队列 table model 578 | setTableModel(inputProcessTable, inputProcessTableModel); 579 | 580 | // 设置输出队列 table model 581 | setTableModel(outputProcessTable, outputProcessTableModel); 582 | 583 | // 设置输入队列 584 | 585 | setTableModel(createProcessTable,inputProcessTableModel); 586 | } 587 | 588 | public void showMainFrameWindow() { 589 | mainFrame.setVisible(true); 590 | } 591 | 592 | private void setTableModel(JTable table, TableModel tableModel) { 593 | // 设置model 594 | table.setModel(tableModel); 595 | // 设置居中显示 596 | DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();//单元格渲染器 597 | tcr.setHorizontalAlignment(JLabel.CENTER);//居中显示 598 | table.setDefaultRenderer(Object.class, tcr);//设置渲染器 599 | // 设置table行宽 600 | table.setRowHeight(17); 601 | // 设置JTable的内容的字体大小 602 | table.setFont(new Font("Menu.font", Font.PLAIN, 15)); 603 | } 604 | 605 | 606 | } 607 | -------------------------------------------------------------------------------- /src/main/view/MainFrame.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Created by JFormDesigner on Fri Nov 02 13:04:22 CST 2018 3 | */ 4 | 5 | package main.view; 6 | 7 | import java.awt.*; 8 | import javax.swing.*; 9 | import javax.swing.border.*; 10 | 11 | /** 12 | * @author jframe 13 | */ 14 | public class MainFrame extends JFrame { 15 | public MainFrame() { 16 | initComponents(); 17 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 18 | setTitle("进程调度模拟系统"); 19 | } 20 | 21 | private void initComponents() { 22 | // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents 23 | menuBar1 = new JMenuBar(); 24 | menu1 = new JMenu(); 25 | loadMenuItem = new JMenuItem(); 26 | mainTabbedPane = new JTabbedPane(); 27 | createProcessPanel = new JPanel(); 28 | panel3 = new JPanel(); 29 | initialBtn = new JButton(); 30 | printerJFT = new JTextField(); 31 | label1 = new JLabel(); 32 | label3 = new JLabel(); 33 | label5 = new JLabel(); 34 | panel4 = new JPanel(); 35 | label6 = new JLabel(); 36 | label7 = new JLabel(); 37 | label8 = new JLabel(); 38 | label9 = new JLabel(); 39 | label11 = new JLabel(); 40 | processNameJFT = new JTextField(); 41 | submitTimeJFT = new JTextField(); 42 | serveTimeJFT = new JTextField(); 43 | printerReqJFT = new JTextField(); 44 | newProcessBtn = new JButton(); 45 | label18 = new JLabel(); 46 | priorityJFT = new JTextField(); 47 | LoadFileBtn = new JButton(); 48 | scrollPane6 = new JScrollPane(); 49 | createProcessTable = new JTable(); 50 | panel5 = new JPanel(); 51 | label12 = new JLabel(); 52 | noGrabRadioBtn = new JRadioButton(); 53 | grabRadioBtnButton2 = new JRadioButton(); 54 | startBtn = new JButton(); 55 | panel6 = new JPanel(); 56 | label13 = new JLabel(); 57 | scrollPane1 = new JScrollPane(); 58 | currentProcessTable = new JTable(); 59 | label19 = new JLabel(); 60 | currentTimeJFT = new JLabel(); 61 | label24 = new JLabel(); 62 | currentPrinterJFT = new JLabel(); 63 | blockBtn = new JButton(); 64 | panel7 = new JPanel(); 65 | label14 = new JLabel(); 66 | scrollPane2 = new JScrollPane(); 67 | readyProcessTable = new JTable(); 68 | panel8 = new JPanel(); 69 | label15 = new JLabel(); 70 | scrollPane3 = new JScrollPane(); 71 | blockProcessTable = new JTable(); 72 | wakeBtn = new JButton(); 73 | resetBtn = new JButton(); 74 | exitBtn = new JButton(); 75 | pauseBtn = new JButton(); 76 | continueBtn = new JButton(); 77 | panel2 = new JPanel(); 78 | panel1 = new JPanel(); 79 | label16 = new JLabel(); 80 | scrollPane4 = new JScrollPane(); 81 | inputProcessTable = new JTable(); 82 | panel9 = new JPanel(); 83 | label17 = new JLabel(); 84 | scrollPane5 = new JScrollPane(); 85 | outputProcessTable = new JTable(); 86 | label21 = new JLabel(); 87 | avgWeightTurnTime = new JLabel(); 88 | avgTurnTime = new JLabel(); 89 | label20 = new JLabel(); 90 | 91 | //======== this ======== 92 | Container contentPane = getContentPane(); 93 | contentPane.setLayout(null); 94 | 95 | //======== menuBar1 ======== 96 | { 97 | menuBar1.setVisible(false); 98 | 99 | //======== menu1 ======== 100 | { 101 | menu1.setText("\u6587\u4ef6"); 102 | 103 | //---- loadMenuItem ---- 104 | loadMenuItem.setText("\u5bfc\u5165"); 105 | menu1.add(loadMenuItem); 106 | } 107 | menuBar1.add(menu1); 108 | } 109 | setJMenuBar(menuBar1); 110 | 111 | //======== mainTabbedPane ======== 112 | { 113 | 114 | //======== createProcessPanel ======== 115 | { 116 | createProcessPanel.setLayout(null); 117 | 118 | //======== panel3 ======== 119 | { 120 | panel3.setBorder(new EtchedBorder()); 121 | panel3.setLayout(null); 122 | 123 | //---- initialBtn ---- 124 | initialBtn.setText("\u8bbe\u7f6e\u6253\u5370\u673a"); 125 | panel3.add(initialBtn); 126 | initialBtn.setBounds(510, 5, 115, 45); 127 | panel3.add(printerJFT); 128 | printerJFT.setBounds(120, 20, 64, 30); 129 | 130 | //---- label1 ---- 131 | label1.setText("\u521d\u59cb\u8bbe\u7f6e"); 132 | panel3.add(label1); 133 | label1.setBounds(5, 0, 55, 25); 134 | 135 | //---- label3 ---- 136 | label3.setText("\u6253\u5370\u673a"); 137 | label3.setHorizontalAlignment(SwingConstants.CENTER); 138 | panel3.add(label3); 139 | label3.setBounds(50, 20, 66, 27); 140 | 141 | //---- label5 ---- 142 | label5.setText("\u53f0"); 143 | label5.setHorizontalAlignment(SwingConstants.CENTER); 144 | panel3.add(label5); 145 | label5.setBounds(180, 20, 45, 27); 146 | 147 | { 148 | // compute preferred size 149 | Dimension preferredSize = new Dimension(); 150 | for(int i = 0; i < panel3.getComponentCount(); i++) { 151 | Rectangle bounds = panel3.getComponent(i).getBounds(); 152 | preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width); 153 | preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height); 154 | } 155 | Insets insets = panel3.getInsets(); 156 | preferredSize.width += insets.right; 157 | preferredSize.height += insets.bottom; 158 | panel3.setMinimumSize(preferredSize); 159 | panel3.setPreferredSize(preferredSize); 160 | } 161 | } 162 | createProcessPanel.add(panel3); 163 | panel3.setBounds(5, 10, 715, 55); 164 | 165 | //======== panel4 ======== 166 | { 167 | panel4.setBorder(new EtchedBorder()); 168 | panel4.setLayout(null); 169 | 170 | //---- label6 ---- 171 | label6.setText("\u65b0\u5efa\u8fdb\u7a0b"); 172 | panel4.add(label6); 173 | label6.setBounds(5, 5, 60, label6.getPreferredSize().height); 174 | 175 | //---- label7 ---- 176 | label7.setText("\u8fdb\u7a0b\u540d\u79f0 "); 177 | label7.setHorizontalAlignment(SwingConstants.CENTER); 178 | panel4.add(label7); 179 | label7.setBounds(45, 20, 70, 25); 180 | 181 | //---- label8 ---- 182 | label8.setText("\u63d0\u4ea4\u65f6\u95f4"); 183 | label8.setHorizontalAlignment(SwingConstants.CENTER); 184 | panel4.add(label8); 185 | label8.setBounds(130, 20, 70, 25); 186 | 187 | //---- label9 ---- 188 | label9.setText("\u670d\u52a1\u65f6\u95f4"); 189 | label9.setHorizontalAlignment(SwingConstants.CENTER); 190 | panel4.add(label9); 191 | label9.setBounds(195, 20, 70, 25); 192 | 193 | //---- label11 ---- 194 | label11.setText("\u6253\u5370\u673a\u8bf7\u6c42\u6570\u91cf"); 195 | label11.setHorizontalAlignment(SwingConstants.CENTER); 196 | panel4.add(label11); 197 | label11.setBounds(345, 20, 105, 25); 198 | panel4.add(processNameJFT); 199 | processNameJFT.setBounds(45, 50, 69, 25); 200 | panel4.add(submitTimeJFT); 201 | submitTimeJFT.setBounds(130, 50, 64, 25); 202 | panel4.add(serveTimeJFT); 203 | serveTimeJFT.setBounds(200, 50, 64, 25); 204 | panel4.add(printerReqJFT); 205 | printerReqJFT.setBounds(365, 50, 64, 25); 206 | 207 | //---- newProcessBtn ---- 208 | newProcessBtn.setText("\u65b0\u5efa\u8fdb\u7a0b"); 209 | panel4.add(newProcessBtn); 210 | newProcessBtn.setBounds(480, 20, 100, 45); 211 | 212 | //---- label18 ---- 213 | label18.setText("\u4f18\u5148\u7ea7"); 214 | label18.setHorizontalAlignment(SwingConstants.CENTER); 215 | panel4.add(label18); 216 | label18.setBounds(275, 25, 50, label18.getPreferredSize().height); 217 | panel4.add(priorityJFT); 218 | priorityJFT.setBounds(275, 50, 64, 25); 219 | 220 | //---- LoadFileBtn ---- 221 | LoadFileBtn.setText("\u5bfc\u5165\u6587\u4ef6"); 222 | panel4.add(LoadFileBtn); 223 | LoadFileBtn.setBounds(595, 20, 100, 45); 224 | 225 | //======== scrollPane6 ======== 226 | { 227 | scrollPane6.setViewportView(createProcessTable); 228 | } 229 | panel4.add(scrollPane6); 230 | scrollPane6.setBounds(15, 80, 680, 95); 231 | } 232 | createProcessPanel.add(panel4); 233 | panel4.setBounds(5, 60, 715, 180); 234 | 235 | //======== panel5 ======== 236 | { 237 | panel5.setBorder(new EtchedBorder()); 238 | panel5.setLayout(null); 239 | 240 | //---- label12 ---- 241 | label12.setText("\u8bf7\u9009\u62e9\u6a21\u62df\u65b9\u6cd5\uff1a"); 242 | label12.setHorizontalAlignment(SwingConstants.CENTER); 243 | panel5.add(label12); 244 | label12.setBounds(15, 15, 125, 25); 245 | 246 | //---- noGrabRadioBtn ---- 247 | noGrabRadioBtn.setText("\u975e\u62a2\u5360\u5f0f\u4f18\u5148\u8c03\u5ea6"); 248 | noGrabRadioBtn.setSelected(true); 249 | panel5.add(noGrabRadioBtn); 250 | noGrabRadioBtn.setBounds(165, 15, 140, noGrabRadioBtn.getPreferredSize().height); 251 | 252 | //---- grabRadioBtnButton2 ---- 253 | grabRadioBtnButton2.setText("\u62a2\u5360\u5f0f\u4f18\u5148\u8c03\u5ea6"); 254 | panel5.add(grabRadioBtnButton2); 255 | grabRadioBtnButton2.setBounds(340, 20, 140, 19); 256 | 257 | //---- startBtn ---- 258 | startBtn.setText("\u5f00\u59cb\u6a21\u62df"); 259 | panel5.add(startBtn); 260 | startBtn.setBounds(530, 10, 110, 35); 261 | } 262 | createProcessPanel.add(panel5); 263 | panel5.setBounds(5, 240, 715, 50); 264 | 265 | //======== panel6 ======== 266 | { 267 | panel6.setBorder(new EtchedBorder()); 268 | panel6.setLayout(null); 269 | 270 | //---- label13 ---- 271 | label13.setText("\u8fd0\u884c\u8fdb\u7a0b\u961f\u5217"); 272 | panel6.add(label13); 273 | label13.setBounds(5, 5, 120, 25); 274 | 275 | //======== scrollPane1 ======== 276 | { 277 | scrollPane1.setViewportView(currentProcessTable); 278 | } 279 | panel6.add(scrollPane1); 280 | scrollPane1.setBounds(15, 40, 605, 40); 281 | 282 | //---- label19 ---- 283 | label19.setText("\u5f53\u524d\u65f6\u95f4\uff1a"); 284 | panel6.add(label19); 285 | label19.setBounds(150, 10, 75, label19.getPreferredSize().height); 286 | 287 | //---- currentTimeJFT ---- 288 | currentTimeJFT.setHorizontalAlignment(SwingConstants.LEFT); 289 | currentTimeJFT.setText("0"); 290 | currentTimeJFT.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 13)); 291 | currentTimeJFT.setVerticalAlignment(SwingConstants.TOP); 292 | panel6.add(currentTimeJFT); 293 | currentTimeJFT.setBounds(220, 10, 50, 20); 294 | 295 | //---- label24 ---- 296 | label24.setText("\u5f53\u524d\u5269\u4f59\u6253\u5370\u673a\u6570\uff1a"); 297 | panel6.add(label24); 298 | label24.setBounds(295, 10, 125, label24.getPreferredSize().height); 299 | 300 | //---- currentPrinterJFT ---- 301 | currentPrinterJFT.setText("0"); 302 | currentPrinterJFT.setHorizontalAlignment(SwingConstants.LEFT); 303 | currentPrinterJFT.setVerticalAlignment(SwingConstants.TOP); 304 | currentPrinterJFT.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 13)); 305 | panel6.add(currentPrinterJFT); 306 | currentPrinterJFT.setBounds(415, 10, 50, 20); 307 | 308 | //---- blockBtn ---- 309 | blockBtn.setText("\u963b\u585e"); 310 | panel6.add(blockBtn); 311 | blockBtn.setBounds(630, 30, 75, 50); 312 | } 313 | createProcessPanel.add(panel6); 314 | panel6.setBounds(5, 285, 715, 110); 315 | 316 | //======== panel7 ======== 317 | { 318 | panel7.setBorder(new EtchedBorder()); 319 | panel7.setLayout(null); 320 | 321 | //---- label14 ---- 322 | label14.setText("\u5c31\u7eea\u961f\u5217"); 323 | label14.setHorizontalAlignment(SwingConstants.CENTER); 324 | panel7.add(label14); 325 | label14.setBounds(0, 5, 85, 25); 326 | 327 | //======== scrollPane2 ======== 328 | { 329 | scrollPane2.setViewportView(readyProcessTable); 330 | } 331 | panel7.add(scrollPane2); 332 | scrollPane2.setBounds(10, 30, 690, 70); 333 | } 334 | createProcessPanel.add(panel7); 335 | panel7.setBounds(5, 390, 715, 120); 336 | 337 | //======== panel8 ======== 338 | { 339 | panel8.setBorder(new EtchedBorder()); 340 | panel8.setLayout(null); 341 | 342 | //---- label15 ---- 343 | label15.setText("\u963b\u585e\u961f\u5217"); 344 | label15.setHorizontalAlignment(SwingConstants.CENTER); 345 | panel8.add(label15); 346 | label15.setBounds(0, 0, 80, 30); 347 | 348 | //======== scrollPane3 ======== 349 | { 350 | scrollPane3.setViewportView(blockProcessTable); 351 | } 352 | panel8.add(scrollPane3); 353 | scrollPane3.setBounds(10, 30, 615, 70); 354 | 355 | //---- wakeBtn ---- 356 | wakeBtn.setText("\u5524\u9192"); 357 | panel8.add(wakeBtn); 358 | wakeBtn.setBounds(635, 40, 68, 45); 359 | } 360 | createProcessPanel.add(panel8); 361 | panel8.setBounds(5, 510, 715, 105); 362 | 363 | //---- resetBtn ---- 364 | resetBtn.setText("\u91cd\u7f6e"); 365 | createProcessPanel.add(resetBtn); 366 | resetBtn.setBounds(420, 635, 95, 40); 367 | 368 | //---- exitBtn ---- 369 | exitBtn.setText("\u9000\u51fa"); 370 | createProcessPanel.add(exitBtn); 371 | exitBtn.setBounds(630, 635, 90, 40); 372 | 373 | //---- pauseBtn ---- 374 | pauseBtn.setText("\u6682\u505c"); 375 | createProcessPanel.add(pauseBtn); 376 | pauseBtn.setBounds(10, 635, 85, 40); 377 | 378 | //---- continueBtn ---- 379 | continueBtn.setText("\u7ee7\u7eed"); 380 | createProcessPanel.add(continueBtn); 381 | continueBtn.setBounds(190, 635, 85, 40); 382 | 383 | { 384 | // compute preferred size 385 | Dimension preferredSize = new Dimension(); 386 | for(int i = 0; i < createProcessPanel.getComponentCount(); i++) { 387 | Rectangle bounds = createProcessPanel.getComponent(i).getBounds(); 388 | preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width); 389 | preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height); 390 | } 391 | Insets insets = createProcessPanel.getInsets(); 392 | preferredSize.width += insets.right; 393 | preferredSize.height += insets.bottom; 394 | createProcessPanel.setMinimumSize(preferredSize); 395 | createProcessPanel.setPreferredSize(preferredSize); 396 | } 397 | } 398 | mainTabbedPane.addTab("\u8fdb\u7a0b\u521b\u5efa", createProcessPanel); 399 | 400 | //======== panel2 ======== 401 | { 402 | panel2.setLayout(null); 403 | 404 | //======== panel1 ======== 405 | { 406 | panel1.setLayout(null); 407 | 408 | //---- label16 ---- 409 | label16.setText("\u8f93\u5165\u8fdb\u7a0b\u961f\u5217\u60c5\u51b5\uff1a"); 410 | label16.setFont(new Font("\u65b9\u6b63\u8212\u4f53", Font.PLAIN, 18)); 411 | panel1.add(label16); 412 | label16.setBounds(0, 0, 165, 30); 413 | 414 | //======== scrollPane4 ======== 415 | { 416 | scrollPane4.setViewportView(inputProcessTable); 417 | } 418 | panel1.add(scrollPane4); 419 | scrollPane4.setBounds(5, 40, 720, 190); 420 | } 421 | panel2.add(panel1); 422 | panel1.setBounds(0, 0, 730, 255); 423 | 424 | //======== panel9 ======== 425 | { 426 | panel9.setLayout(null); 427 | 428 | //---- label17 ---- 429 | label17.setText("\u6267\u884c\u540e\u8fdb\u7a0b\u961f\u5217\u60c5\u51b5\uff1a"); 430 | label17.setFont(new Font("\u65b9\u6b63\u8212\u4f53", Font.PLAIN, 18)); 431 | panel9.add(label17); 432 | label17.setBounds(5, 0, 190, 50); 433 | 434 | //======== scrollPane5 ======== 435 | { 436 | scrollPane5.setViewportView(outputProcessTable); 437 | } 438 | panel9.add(scrollPane5); 439 | scrollPane5.setBounds(0, 55, 720, 160); 440 | } 441 | panel2.add(panel9); 442 | panel9.setBounds(0, 255, 730, 240); 443 | 444 | //---- label21 ---- 445 | label21.setText("\u5e73\u5747\u5e26\u6743\u5468\u8f6c\u65f6\u95f4\uff1a"); 446 | label21.setFont(new Font("\u65b9\u6b63\u8212\u4f53", Font.PLAIN, 22)); 447 | panel2.add(label21); 448 | label21.setBounds(5, 580, 210, 65); 449 | 450 | //---- avgWeightTurnTime ---- 451 | avgWeightTurnTime.setText("0"); 452 | avgWeightTurnTime.setFont(new Font("\u65b9\u6b63\u8212\u4f53", Font.PLAIN, 22)); 453 | panel2.add(avgWeightTurnTime); 454 | avgWeightTurnTime.setBounds(250, 505, 140, 65); 455 | 456 | //---- avgTurnTime ---- 457 | avgTurnTime.setText("0"); 458 | avgTurnTime.setFont(new Font("\u65b9\u6b63\u8212\u4f53", Font.PLAIN, 22)); 459 | panel2.add(avgTurnTime); 460 | avgTurnTime.setBounds(250, 580, 140, 65); 461 | 462 | //---- label20 ---- 463 | label20.setText("\u5e73\u5747\u5468\u8f6c\u65f6\u95f4\uff1a"); 464 | label20.setFont(new Font("\u65b9\u6b63\u8212\u4f53", Font.PLAIN, 22)); 465 | panel2.add(label20); 466 | label20.setBounds(10, 505, 175, 65); 467 | 468 | { 469 | // compute preferred size 470 | Dimension preferredSize = new Dimension(); 471 | for(int i = 0; i < panel2.getComponentCount(); i++) { 472 | Rectangle bounds = panel2.getComponent(i).getBounds(); 473 | preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width); 474 | preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height); 475 | } 476 | Insets insets = panel2.getInsets(); 477 | preferredSize.width += insets.right; 478 | preferredSize.height += insets.bottom; 479 | panel2.setMinimumSize(preferredSize); 480 | panel2.setPreferredSize(preferredSize); 481 | } 482 | } 483 | mainTabbedPane.addTab("\u7ed3\u679c\u9884\u89c8", panel2); 484 | } 485 | contentPane.add(mainTabbedPane); 486 | mainTabbedPane.setBounds(0, 0, 730, 715); 487 | 488 | { 489 | // compute preferred size 490 | Dimension preferredSize = new Dimension(); 491 | for(int i = 0; i < contentPane.getComponentCount(); i++) { 492 | Rectangle bounds = contentPane.getComponent(i).getBounds(); 493 | preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width); 494 | preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height); 495 | } 496 | Insets insets = contentPane.getInsets(); 497 | preferredSize.width += insets.right; 498 | preferredSize.height += insets.bottom; 499 | contentPane.setMinimumSize(preferredSize); 500 | contentPane.setPreferredSize(preferredSize); 501 | } 502 | pack(); 503 | setLocationRelativeTo(getOwner()); 504 | 505 | //---- buttonGroup1 ---- 506 | ButtonGroup buttonGroup1 = new ButtonGroup(); 507 | buttonGroup1.add(noGrabRadioBtn); 508 | buttonGroup1.add(grabRadioBtnButton2); 509 | // JFormDesigner - End of component initialization //GEN-END:initComponents 510 | } 511 | 512 | // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables 513 | private JMenuBar menuBar1; 514 | private JMenu menu1; 515 | private JMenuItem loadMenuItem; 516 | private JTabbedPane mainTabbedPane; 517 | private JPanel createProcessPanel; 518 | private JPanel panel3; 519 | private JButton initialBtn; 520 | private JTextField printerJFT; 521 | private JLabel label1; 522 | private JLabel label3; 523 | private JLabel label5; 524 | private JPanel panel4; 525 | private JLabel label6; 526 | private JLabel label7; 527 | private JLabel label8; 528 | private JLabel label9; 529 | private JLabel label11; 530 | private JTextField processNameJFT; 531 | private JTextField submitTimeJFT; 532 | private JTextField serveTimeJFT; 533 | private JTextField printerReqJFT; 534 | private JButton newProcessBtn; 535 | private JLabel label18; 536 | private JTextField priorityJFT; 537 | private JButton LoadFileBtn; 538 | private JScrollPane scrollPane6; 539 | private JTable createProcessTable; 540 | private JPanel panel5; 541 | private JLabel label12; 542 | private JRadioButton noGrabRadioBtn; 543 | private JRadioButton grabRadioBtnButton2; 544 | private JButton startBtn; 545 | private JPanel panel6; 546 | private JLabel label13; 547 | private JScrollPane scrollPane1; 548 | private JTable currentProcessTable; 549 | private JLabel label19; 550 | private JLabel currentTimeJFT; 551 | private JLabel label24; 552 | private JLabel currentPrinterJFT; 553 | private JButton blockBtn; 554 | private JPanel panel7; 555 | private JLabel label14; 556 | private JScrollPane scrollPane2; 557 | private JTable readyProcessTable; 558 | private JPanel panel8; 559 | private JLabel label15; 560 | private JScrollPane scrollPane3; 561 | private JTable blockProcessTable; 562 | private JButton wakeBtn; 563 | private JButton resetBtn; 564 | private JButton exitBtn; 565 | private JButton pauseBtn; 566 | private JButton continueBtn; 567 | private JPanel panel2; 568 | private JPanel panel1; 569 | private JLabel label16; 570 | private JScrollPane scrollPane4; 571 | private JTable inputProcessTable; 572 | private JPanel panel9; 573 | private JLabel label17; 574 | private JScrollPane scrollPane5; 575 | private JTable outputProcessTable; 576 | private JLabel label21; 577 | private JLabel avgWeightTurnTime; 578 | private JLabel avgTurnTime; 579 | private JLabel label20; 580 | // JFormDesigner - End of variables declaration //GEN-END:variables 581 | 582 | 583 | public JButton getInitialBtn() { 584 | return initialBtn; 585 | } 586 | 587 | public JTextField getPrinterJFT() { 588 | return printerJFT; 589 | } 590 | 591 | public JTextField getProcessNameJFT() { 592 | return processNameJFT; 593 | } 594 | 595 | public JTextField getSubmitTimeJFT() { 596 | return submitTimeJFT; 597 | } 598 | 599 | public JTextField getServeTimeJFT() { 600 | return serveTimeJFT; 601 | } 602 | 603 | public JTextField getPrinterReqJFT() { 604 | return printerReqJFT; 605 | } 606 | 607 | public JButton getNewProcessBtn() { 608 | return newProcessBtn; 609 | } 610 | 611 | public JButton getLoadFileBtn(){return LoadFileBtn;} 612 | 613 | public JRadioButton getNoGrabRadioBtn() { 614 | return noGrabRadioBtn; 615 | } 616 | 617 | public JRadioButton getGrabRadioBtnButton2() { 618 | return grabRadioBtnButton2; 619 | } 620 | 621 | public JButton getStartBtn() { 622 | return startBtn; 623 | } 624 | 625 | public JTable getCurrentProcessTable() { 626 | return currentProcessTable; 627 | } 628 | 629 | public JButton getBlockBtn() { 630 | return blockBtn; 631 | } 632 | 633 | public JButton getPauseBtn() { 634 | return pauseBtn; 635 | } 636 | 637 | public JButton getContinueBtn() { 638 | return continueBtn; 639 | } 640 | 641 | public JTable getReadyProcessTable() { 642 | return readyProcessTable; 643 | } 644 | 645 | public JTable getBlockProcessTable() { 646 | return blockProcessTable; 647 | } 648 | 649 | public JTable getCreateProcessTable(){return createProcessTable;} 650 | 651 | public JButton getWakeBtn() { 652 | return wakeBtn; 653 | } 654 | 655 | public JButton getResetBtn() { 656 | return resetBtn; 657 | } 658 | 659 | public JButton getExitBtn() { 660 | return exitBtn; 661 | } 662 | 663 | public JTextField getPriorityJFT() { 664 | return priorityJFT; 665 | } 666 | 667 | public JLabel getCurrentTimeJFT() { 668 | return currentTimeJFT; 669 | } 670 | 671 | public JTabbedPane getMainTabbedPane() { 672 | return mainTabbedPane; 673 | } 674 | 675 | public JTable getInputProcessTable() { 676 | return inputProcessTable; 677 | } 678 | 679 | public JTable getOutputProcessTable() { 680 | return outputProcessTable; 681 | } 682 | 683 | public JMenuItem getLoadMenuItem() { 684 | return loadMenuItem; 685 | } 686 | 687 | public JLabel getAvgTurnTime() { 688 | return avgTurnTime; 689 | } 690 | 691 | public JLabel getAvgWeightTurnTime() { 692 | return avgWeightTurnTime; 693 | } 694 | 695 | public JLabel getCurrentPrinterJFT() { 696 | return currentPrinterJFT; 697 | } 698 | } 699 | --------------------------------------------------------------------------------