⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainframe.java

📁 一个简单的操作系统模拟程序 java+swing 可进行一般的文件操作 进程建立及删除等
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    private javax.swing.JScrollPane jScrollPane9;
    private javax.swing.JMenuItem pauseMenuItem;
    private javax.swing.JProgressBar ramUsageBar;
    private javax.swing.JLabel ramUsageLabel;
    private javax.swing.JTextArea readyProcArea;
    private javax.swing.JLabel readyProcLabel;
    private javax.swing.JMenuItem resumeMenuItem;
    private javax.swing.JLabel runningPIDDisplayLabel;
    private javax.swing.JLabel runningPIDPromptLabel;
    private javax.swing.JLabel runningProcessNameDisplayLabel;
    private javax.swing.JLabel runningRrocessNamePromptLabel;
    private javax.swing.JMenuItem shutdownMenuItem;
    private javax.swing.JLabel sysTimeDisplayLabel;
    private javax.swing.JLabel sysTimePromptLabel;
    private javax.swing.JMenu systemMenu;
    private javax.swing.JMenuItem systemTipMenuItem;
    private javax.swing.JTextArea tempResultArea;
    private javax.swing.JLabel tempResultLabel;
    private javax.swing.JLabel timeSegmentDisplayLabel;
    private javax.swing.JLabel timeSegmentPromptLabel;
    // End of variables declaration//GEN-END:variables
    
    private Disk simDisk;//the simulation hard-disk for the system
    private String sysPrompt;//the system prompt string
    private ExtDefaultTreeModel treeModel;//the data model for the file tree
    private DefaultMutableTreeNode rootNode;//the root tree node for the system 
    private int sysTime;//the system time
    private Kernel sysKernel;//the system kernel
    private javax.swing.Timer sysClock;//the global clock for the system
    private int sysBaseClock;//the base clock for the system
    
    private class Kernel implements ActionListener{
        
        public Kernel(Disk simDisk){
            //device initialize code
            sysDeviceA = new Device('A');//create the device A
            sysDeviceB = new Device('B');//create the device B
            sysDeviceC = new Device('C');//create the device C
            devAWaitingList = new ArrayList();//create the device A waiting list
            devBWaitingList = new ArrayList();//create the device B waiting list
            devCWaitingList = new ArrayList();//create the device C waiting list
            
            //disk initialize code
            sysDisk = simDisk;
            
            //cpu initialize code
            sysCPU = new CPU(devAWaitingList,devBWaitingList,devCWaitingList);//create the cpu for the system
            blankPCB = new ArrayList();//create the blank PCB waiting list
            blockPCB = new ArrayList();//create the block PCB waiting list
            readyPCB = new ArrayList();//create the ready PCB waiting list
            //create the pcb number from 0 to 9
            PCB pcb0 = new PCB(0);//the pcb 0 is used for the idle process
            PCB pcb1 = new PCB(1);
            blankPCB.add(pcb1);
            PCB pcb2 = new PCB(2);
            blankPCB.add(pcb2);
            PCB pcb3 = new PCB(3);
            blankPCB.add(pcb3);
            PCB pcb4 = new PCB(4);
            blankPCB.add(pcb4);
            PCB pcb5 = new PCB(5);
            blankPCB.add(pcb5);
            PCB pcb6 = new PCB(6);
            blankPCB.add(pcb6);
            PCB pcb7 = new PCB(7);
            blankPCB.add(pcb7);
            PCB pcb8 = new PCB(8);
            blankPCB.add(pcb8);
            PCB pcb9 = new PCB(9);
            blankPCB.add(pcb9);
            
            //ram initializ code
            sysRAM = new RAM();//create the ram for the system
            
            //the process initialized code
            //the code below create the idle process
            ArrayList idleInstruction = new ArrayList();//create a instrucion array
//            idleInstruction.add("Ax1");
//            idleInstruction.add("AX1");
//            idleInstruction.add("BY");
//            idleInstruction.add("By");
//            idleInstruction.add("Cz");
//            idleInstruction.add("CZ");
//            idleInstruction.add("DA3");
            idleInstruction.add("E");//add a instruction into  it
            int idleInstructionLength = idleInstruction.size();//get the idle process instruction lengt
            int ramOffset = sysRAM.requestSpace(idleInstructionLength + 12);//request for ram space
            pcb0.initialize("Idle",idleInstruction,idleInstructionLength,ramOffset,idleInstructionLength,null);//fill the information into the target PCB,then initialized it
            sysCPU.load(pcb0);//load the process into the cpu
            
            //initialize the system clock
            sysTime = 0;
            //initialize the timeSegment clock
            timeSegment = 5;
            
            //initialize the ram usage bar
            this.updateRAM();
            
        }
        
        public void actionPerformed(ActionEvent evt){
            //system clock management
            sysTime ++;//increase the system clock
            sysTimeDisplayLabel.setText(Integer.toString(sysTime) + " sec");
            timeSegment --;//decrease the timeSegment clock
            
            if(timeSegment < 0){// the time segment is exhaust,switch context
                //unload the process from the cpu
                PCB tmpPCB = sysCPU.getProcess();
                sysCPU.unload();//unload  the job
                sysCPU.reset();//reset the cpu
                readyPCB.add(tmpPCB);//put the process back to the ready list
                
                //load the process from the ready list
                tmpPCB = (PCB)readyPCB.remove(0);
                this.readyPCBDisplay();
                sysCPU.load(tmpPCB);
                timeSegment = 4;
                timeSegmentDisplayLabel.setText(Integer.toString(timeSegment) + " sec");
            } else {// if the time segment is not exhaust 
                timeSegmentDisplayLabel.setText(Integer.toString(timeSegment) + " sec");
            }
            
            //process information display managment
            runningPIDDisplayLabel.setText(Integer.toString(sysCPU.getProcess().getID()));
            runningProcessNameDisplayLabel.setText(sysCPU.getProcess().getName());
            IRDisplayLabel.setText(sysCPU.getProcess().getInstruction());
            
            //cpu management
            sysCPU.run();
            if((sysCPU.getPSW())[2] == 1){//if the program has been terminate,destory it and then load the new one into the cpu
                PCB tmpPCB;
                tmpPCB = sysCPU.getProcess();//save the pcb
                sysCPU.unload();//unload the job from the cpu
                sysCPU.reset();//reset the cpu
                
                if(tmpPCB.getID() == 0){ //deal with the pcb that unload from the cpu 
                    readyPCB.add(tmpPCB);//if the process is the idle process
                } else {
                    this.destory(tmpPCB);//if not,destory it
                }
                
                tmpPCB = (PCB)readyPCB.remove(0);//get the new PCB
                this.readyPCBDisplay();
                sysCPU.load(tmpPCB);//load the new job to the cpu
                timeSegment = 5;//reset the time Segment
                tempResultArea.setText("");
            } else if((sysCPU.getPSW())[3] == 1){//if the program meet the illegal instruction
                        PCB tmpPCB;
                        tmpPCB = sysCPU.getProcess();//save the pcb
                        sysCPU.unload();//unload the job from the cpu
                        sysCPU.reset();//reset the cpu
                        this.kill(tmpPCB);//kill the process
                        tmpPCB = (PCB)readyPCB.remove(0);
                        this.readyPCBDisplay();//reflash the ready list area
                        sysCPU.load(tmpPCB);//load the new job to the cpu
                        timeSegment = 5;//reset the time Segment
                        tempResultArea.setText("");
                    } else if((sysCPU.getPSW())[4] == 1){//if the process meets the I/O instruction
                                PCB tmpPCB;
                                tmpPCB = sysCPU.getProcess();
                                sysCPU.unload();
                                sysCPU.reset();
                                this.block(tmpPCB);
                                
                                tmpPCB = (PCB)readyPCB.remove(0);//get the new PCB
                                sysCPU.load(tmpPCB);//load the new job to the cpu
                                timeSegment = 5;//reset the time Segment
                                tempResultArea.setText("");
                            } else { //there is nothing happen,update the temp result display area
                                char[] variable;
                                tempResultArea.setText("");
                                for(Iterator variableListIterator = sysCPU.getProcess().getVariableList().iterator();variableListIterator.hasNext();){
                                    variable = (char[])variableListIterator.next();
                                    tempResultArea.append(String.valueOf(variable[0]) + "=" + String.valueOf((int)variable[1]) + "\n");
                                }
                            }
            
            //device management
            if(sysDeviceA.getState() == 0){//if the device is idle,maybe the job has been finish ,or the device will have job to do
                if(sysDeviceA.getInterruptRequestBit() == 1){//job finfish
                    sysDeviceA.clearInterrupt();//respond to the device's interrupt'
                    DRCB tmpDRCB = sysDeviceA.getDRCB();//get the request control block
                    PCB tmpPCB = tmpDRCB.getRequestProcess();//get the process control block from the request block
                    this.awake(tmpPCB);
                }
                //to check if there is  job to do
                if(devAWaitingList.size() != 0){//if the device have job to do
                    DRCB tmpDRCB;
                    tmpDRCB = (DRCB)devAWaitingList.remove(0);//get the job
                    sysDeviceA.load(tmpDRCB);
                    sysDeviceA.run();
                }
            } else {//the device is busy
                sysDeviceA.run();
            }
            this.devAWaitingListDisplay();
        
            if(sysDeviceB.getState() == 0){//if the device is idle,maybe the job has been finish ,or the device will have job to do
                if(sysDeviceB.getInterruptRequestBit() == 1){//job finfish
                    sysDeviceB.clearInterrupt();//respond to the device's interrupt'
                    DRCB tmpDRCB = sysDeviceB.getDRCB();//get the request control block
                    PCB tmpPCB = tmpDRCB.getRequestProcess();//get the process control block from the request block
                    this.awake(tmpPCB);
                }
                //to check if there is  job to do
                if(devBWaitingList.size() != 0){//if the de

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -