其他分享
首页 > 其他分享> > 操作系统实验1

操作系统实验1

作者:互联网

实验1《CPU Scheduling》
一、实验目的
  多道系统中,当就绪进程数大于处理机数时,须按照某种策略决定哪些进程优先占用处理机。本实验模拟实现处理机调度,加深了解处理机调度的工作过程。

二、实验内容
   选择一个调度算法,实现处理机调度。
  1、设计一个按优先权调度算法实现处理机调度的程序;
  2、设计按时间片轮转实现处理机调度的程序。

三、实验方法
  本人选择的是设计一个按优先权调度算法,和时间片轮转算法实现处理机调度的程序,实验工具是NetBeans IDE 8.2,采用图形界面和代码实现。

四、实验步骤
1、需求分析
  ① 可随机输入若干进程,并按优先级排序;
  ② 采用动态优先权调度,从就绪队首选进程运行,要求运行一个时间单位后,优先权减1,运行时间减1,运行时间为0时,撤销该进程;
  ③ 尽量采用图形界面;
  ④ 可动态增加进程;
  ⑤ 规定道数,设置后备队列和挂起状态;
  ⑥ 如果内存中进程少于规定道数,可自动从后备队列通过作业调度选择一作业进入,作业调度算法可自行选择;
  ⑦ 被挂起进程入挂起队列,设置解挂功能用于将指定挂起进程解挂并入就绪队列;
  ⑧ 每次调度后,显示各进程状态。

2、概要设计
  ① 首先进行图形界面设计,分为添加进程、后备队列、就绪队列、CPU运行进程、挂起队列、终止进程,分别含有进程名、优先权、运行时间等信息,将这些信息使用一个jlist来存储含有这些信息的字符串
  ② 设计添加进程,用户可以直接输入进程名、运行时间及选择优先级从而添加进程到后备队列。
  ④ 在后备队列中添加运行按钮,点击之后可以根据道数选择多少个进程进入就绪队列,同时删除后备队列中的进程
  ⑤ 设置就绪队列中的挂起状态,选中进程名然后点击挂起时,该进程的所有信息从就绪队列中退出,进入到挂起进程队列中。
  ⑥ 挂起进程队列中设置解挂按钮,选中进程后点击解挂按钮该进程进入到就绪队列中,就绪队列中所有进程按优先级重新排序显示并进入CPU。
  ⑦ 在就绪队列中设置next按钮,点击一次就相当于CPU中的进程运行一次,该进程的优先级和运行时间均减1,当时间减到0的时候,将进程从就绪队列删去,添加到终止进程,就绪队列中的所有进程重新按优先级排序,第一个进程进入CPU中运行。
  ⑧ CPU中的道数设置,通过下拉框实现。当数字改变时,就绪队列中的进程数也随之进行对应的改变。
在这里插入图片描述

3、详细设计

  1. 前端界面,这里主要使用了jFrame,jComboBox,jlist作为显示容器
  2. 设置 四个全局的Arraylist数组分别表示 就绪队列,挂起队列,后备队列,终止队列。同时有一个更新所有jList的方法(这样可以方便代码的复用性)
    ArrayList< pcb> pcb_jiuxu = new ArrayList< pcb >();
    ArrayList< pcb> pcb_guaqi = new ArrayList< pcb >();
    ArrayList< pcb > pcb_zhongzhi = new ArrayList< pcb >();
    ArrayList< pcb > pcb_houbei = new ArrayList< pcb >();

这个是四个全局变量

public void new_genxin()
    {
         int p_size=pcb_jiuxu.size();
           String []str=new String[p_size];
           for(int i=0;i<p_size;i++)
           {
            str[i]=get_pcb(pcb_jiuxu.get(i));
           }
            jList6.setListData(str);
            //更新就绪队列的jlist6
            
            
            int p_size1=pcb_houbei.size();
            String []str1=new String[p_size1];
            for(int i=0;i<p_size1;i++)
           {
            str1[i]=get_pcb(pcb_houbei.get(i));
           }
            jList5.setListData(str1);
            
            //更新后备队列的jlist5
            
            int p_size2=pcb_guaqi.size();
            String []str2=new String[p_size2];
            for(int i=0;i<p_size2;i++)
           {
            str2[i]=get_pcb(pcb_guaqi.get(i));
           }
            jList8.setListData(str2);
            
            //更新挂起队列
            
             int p_size3=pcb_zhongzhi.size();
            String []str3=new String[p_size3];
            for(int i=0;i<p_size3;i++)
           {
            str3[i]=get_pcb(pcb_zhongzhi.get(i));
           }
            jList7.setListData(str3);
            
            //更新终止队列
            
            
            
            
            
            
    }
    这里是可以更新jFrame所有容器的函数
  1. 接下来首先看添加进程,这是点击 添加按钮,触发了mouseClicked事件,mouseClicked中的内容如下
 String name=jTextField1.getText();
        String time=jTextField4.getText();
        String rank=jComboBox1.getSelectedItem().toString();
        
        String name1=jTextField2.getText();
        String time1=jTextField5.getText();
        String rank1=jComboBox2.getSelectedItem().toString();
        
        String name2=jTextField3.getText();
        String time2=jTextField6.getText();
        String rank2=jComboBox3.getSelectedItem().toString();
        pcb pcb_1=new pcb(name,time,rank);
        pcb pcb_2=new pcb(name1,time1,rank1);
        pcb pcb_3=new pcb(name2,time2,rank2);
        
        
        pcb_houbei.add(pcb_1);
        pcb_houbei.add(pcb_2);
        pcb_houbei.add(pcb_3);
        int size=pcb_houbei.size();
        String []str=new String[size];
        for(int i=0;i<size;i++)
        {
            str[i]=get_pcb(pcb_houbei.get(i));
        }
       jList5.setListData(str);//将读入的东西放在jList中显示

在这里插入图片描述例如添加的进程进入后备队列的样例

4.点击时间片运转,会以先来先服务的算法将进程按照指定的道数调入就绪队列

 int dao_num=Integer.parseInt(jComboBox4.getSelectedItem().toString());
        
        while(dao_num!=0)
        {
            dao_num--;
            if(pcb_houbei.size()>0)
            {
                  pcb_jiuxu.add(pcb_houbei.get(0));
                  pcb_houbei.remove(0);
            }
            else break;
            new_genxin();

5.点击优先权调度,会按照指定的道数,根据每一个进程的优先权的高低,从高到低依次选择进程调入就绪队列

 private void jButton9MouseClicked(java.awt.event.MouseEvent evt) {                                      
        // TODO add your handling code here:
        int dao_num=Integer.parseInt(jComboBox4.getSelectedItem().toString());
        
        pcb_sort(pcb_houbei);
        while(dao_num!=0)
        {
            dao_num--;
            if(pcb_houbei.size()>0)
            {
                  pcb_jiuxu.add(pcb_houbei.get(0));
                  pcb_houbei.remove(0);
            }
            else break;
          
        }
          new_genxin();
        

补充一下,上面函数中的pcb_sort是自己写的一个根据优先级大小在 arraylist中进行排序的一个函数,下面这是代码

public  ArrayList<pcb> pcb_sort( ArrayList<pcb> par)
    {
        int p_size=par.size();
        
        for(int i=0;i<p_size;i++)
        {
            for(int j=0;j<i;j++)
            {
                pcb a=par.get(i);
                pcb b=par.get(j);
                
                pcb temp;
                int rank1=Integer.parseInt(a.rank);
                int rank2=Integer.parseInt(b.rank);
                
                if(rank1>rank2)
                {
                    par.set(i, b);
                    par.set(j, a);
                }
                
                
            }
        }
        return par;
    }

6.接着在就绪队里下面,如果点击优先权调度算法则会按照优先权调度算法每一次选出优先权最高的放如cpu中,然后将时间和优先级都减一后放入就绪队列重现排序后进入下一轮调度,这里如果就绪队列中的进城数目小于规定的道数话,如果后备队列 有进程的话,会自动从后备队列调入

  pcb_sort(pcb_jiuxu);//对数组按照指定的办法进行排序
        
        
        pcb p_temp=pcb_jiuxu.get(0);
        pcb_jiuxu.remove(0);
        String name=p_temp.name;
        String rank=p_temp.rank;
        String time=p_temp.time;
        
        int time_to_int=Integer.parseInt(time);
        int rank_to_int=Integer.parseInt(rank);
        
        //使用pcb_ptemp3表示删掉旧的进程pcb
       
        time_to_int--;
        rank_to_int--;
    
        if(time_to_int>0)
        {
              pcb p_temp2=new pcb(name,String.valueOf(time_to_int),String.valueOf( rank_to_int));
               pcb_jiuxu.add( p_temp2);
               
               
              
             
           
             
             int p_size=pcb_jiuxu.size();
             String []str=new String[p_size];
             
             for(int i=0;i<p_size;i++)
             {
               str[i]=get_pcb(pcb_jiuxu.get(i));
             }
             
             
             new_genxin();
             
        }
        else
        {
            //删掉旧的pcb
          
            
            pcb p_temp2=new pcb(name,String.valueOf(time_to_int),String.valueOf(rank_to_int)); 
            pcb_jiuxu.remove(p_temp2);
            pcb_zhongzhi.add(p_temp2);
            new_genxin();
            
//                       int p_size=pcb_zhongzhi.size();
//             String []str=new String[p_size];
//             for(int i=0;i<p_size;i++)
//            {
//                str[i]=get_pcb(pcb_zhongzhi.get(i));
//            }
//            jList7.setListData(str);
        }
       
        
        //设置cpu显示
        jTextField7.setText(name);
        jTextField8.setText(time);
        jTextField9.setText(rank);
        
        
        int select_index=jComboBox4.getSelectedIndex();
       
        while(pcb_jiuxu.size()<select_index&&pcb_houbei.size()>0)
        {
            //如果就绪队列里面的进程数小于规定的道数,且后备队列有进程,则将后备队列调入
            pcb_jiuxu.add(pcb_houbei.get(0));
            
            pcb_houbei.remove(0);
            
        }           
        

7.这里如果选用时间片算法,则每一次选出最前面的一个进程,然后时间减一后进入队列的尾部,这里 同理如果时间等于0,则退出就绪队列,进入终止队列

 int time_stamp=Integer.parseInt(jTextField10.getText());
        
        while(time_stamp!=0)
        {
            time_stamp--;
            pcb p_temp=pcb_jiuxu.get(0);
            jTextField7.setText(p_temp.name);
            jTextField8.setText(p_temp.time);
            jTextField9.setText(p_temp.rank);
            
             int time_to_int=Integer.parseInt(p_temp.time);
             int rank_to_int=Integer.parseInt(p_temp.rank);
        
        //使用pcb_ptemp3表示删掉旧的进程pcb
            pcb_jiuxu.remove(0);
            
            
            time_to_int--;
            rank_to_int--;
            
            
             String temp_name=p_temp.name;
            String temp_time=String.valueOf(time_to_int);
            String temp_rank=String.valueOf(rank_to_int);
            pcb p_add_temp=new pcb(temp_name,temp_time,temp_rank);
            if(time_to_int!=0)
            {
                 pcb_jiuxu.add(p_add_temp);
            }
            else
            {
                pcb_zhongzhi.add(p_add_temp);
            }
            
            
            
           new_genxin();
          

8.点击挂起:会吧你选中的从就绪队列中移除,移到挂起队列

 //先找到要挂起的是哪一个
        int select_index=jList6.getSelectedIndex();
        pcb temp=pcb_jiuxu.get(select_index);
        pcb_jiuxu.remove(select_index);
        //删除在就绪队列中所选中的编号
        
        
        
           pcb_guaqi.add(temp);
           
           //调用这个函数更新界面的显示内容
           new_genxin();

9.点击解挂,则会把你选中的要解挂的进程从挂起进程中取出放入就绪 进程

  int select_index=jList8.getSelectedIndex();
          pcb temp=pcb_guaqi.get(select_index);
          pcb_guaqi.remove(select_index);
           pcb_jiuxu.add(0, temp);
           
           
            //调用这个函数更新界面的显示内容
           new_genxin();

五、实验代码

  1. 这里代码分为两块,一个是pcb类的代码如下,申明一个pcb的类
public class pcb {
    static class CompareTime implements Comparator<pcb> {
       
        public int compare(pcb p1, pcb p2) {
            return p2.rank.compareTo(p1.rank);
        }
    }
    
    public String name;
    public String time;
    public String rank;
    public pcb()
    {
        
    }
    
    
    public pcb(String name,String time,String rank)
    {
        this.name=name;
        this.rank=rank;
        this.time=time;
    }
    
    
}

第二类 是实现 的全部代码

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication1;

import java.util.ArrayList;

/**
 *
 * @author lenovo
 */
public class pcb_demo extends javax.swing.JFrame {

    ArrayList< pcb> pcb_jiuxu = new ArrayList< pcb >();
    ArrayList< pcb> pcb_guaqi = new ArrayList< pcb >();
    ArrayList< pcb > pcb_zhongzhi = new ArrayList< pcb >();
    ArrayList< pcb > pcb_houbei = new ArrayList< pcb >();
    
    
    /**
     * Creates new form pcb_demo
     */
    
    public pcb_demo() {
        initComponents();
    }
    public String get_pcb(pcb p)
    {
        String str="进程名";
        str+=p.name;
        str+=" ";
        str+="运行时间";
        str+=p.time;
        str+=" ";
        str+="优先级:";
        str+=p.rank;
        
        
        return str;
        
        
    }
    //按照优先级冒泡排序pcb的数组
    public  ArrayList<pcb> pcb_sort( ArrayList<pcb> par)
    {
        int p_size=par.size();
        
        for(int i=0;i<p_size;i++)
        {
            for(int j=0;j<i;j++)
            {
                pcb a=par.get(i);
                pcb b=par.get(j);
                
                pcb temp;
                int rank1=Integer.parseInt(a.rank);
                int rank2=Integer.parseInt(b.rank);
                
                if(rank1>rank2)
                {
                    par.set(i, b);
                    par.set(j, a);
                }
                
                
            }
        }
        return par;
    }
    public void new_genxin()
    {
         int p_size=pcb_jiuxu.size();
           String []str=new String[p_size];
           for(int i=0;i<p_size;i++)
           {
            str[i]=get_pcb(pcb_jiuxu.get(i));
           }
            jList6.setListData(str);
            //更新就绪队列的jlist6
            
            
            int p_size1=pcb_houbei.size();
            String []str1=new String[p_size1];
            for(int i=0;i<p_size1;i++)
           {
            str1[i]=get_pcb(pcb_houbei.get(i));
           }
            jList5.setListData(str1);
            
            //更新后备队列的jlist5
            
            int p_size2=pcb_guaqi.size();
            String []str2=new String[p_size2];
            for(int i=0;i<p_size2;i++)
           {
            str2[i]=get_pcb(pcb_guaqi.get(i));
           }
            jList8.setListData(str2);
            
            //更新挂起队列
            
             int p_size3=pcb_zhongzhi.size();
            String []str3=new String[p_size3];
            for(int i=0;i<p_size3;i++)
           {
            str3[i]=get_pcb(pcb_zhongzhi.get(i));
           }
            jList7.setListData(str3);
            
            //更新终止队列
            
            
            
            
            
            
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList<>();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jList2 = new javax.swing.JList<>();
        jScrollPane3 = new javax.swing.JScrollPane();
        jList3 = new javax.swing.JList<>();
        jScrollPane4 = new javax.swing.JScrollPane();
        jList4 = new javax.swing.JList<>();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jButton5 = new javax.swing.JButton();
        jComboBox5 = new javax.swing.JComboBox<>();
        jButton8 = new javax.swing.JButton();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jScrollPane6 = new javax.swing.JScrollPane();
        jList6 = new javax.swing.JList<>();
        jButton3 = new javax.swing.JButton();
        jScrollPane8 = new javax.swing.JScrollPane();
        jList8 = new javax.swing.JList<>();
        jButton4 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jTextField10 = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jScrollPane7 = new javax.swing.JScrollPane();
        jList7 = new javax.swing.JList<>();
        jLabel10 = new javax.swing.JLabel();
        jScrollPane5 = new javax.swing.JScrollPane();
        jList5 = new javax.swing.JList<>();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jTextField7 = new javax.swing.JTextField();
        jTextField8 = new javax.swing.JTextField();
        jTextField9 = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jComboBox4 = new javax.swing.JComboBox<>();
        jButton2 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jComboBox1 = new javax.swing.JComboBox<>();
        jTextField2 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jComboBox2 = new javax.swing.JComboBox<>();
        jTextField3 = new javax.swing.JTextField();
        jTextField6 = new javax.swing.JTextField();
        jComboBox3 = new javax.swing.JComboBox<>();
        jButton1 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();

        jList1.setModel(new javax.swing.AbstractListModel<String>() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public String getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(jList1);

        jLabel4.setText("jLabel4");

        jLabel5.setText("jLabel5");

        jLabel6.setText("jLabel6");

        jList2.setModel(new javax.swing.AbstractListModel<String>() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public String getElementAt(int i) { return strings[i]; }
        });
        jScrollPane2.setViewportView(jList2);

        jList3.setModel(new javax.swing.AbstractListModel<String>() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public String getElementAt(int i) { return strings[i]; }
        });
        jScrollPane3.setViewportView(jList3);

        jList4.setModel(new javax.swing.AbstractListModel<String>() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public String getElementAt(int i) { return strings[i]; }
        });
        jScrollPane4.setViewportView(jList4);

        jLabel7.setText("进程名");

        jLabel8.setText("运行时间");

        jLabel9.setText("优先级");

        jButton5.setText("jButton5");
        jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton5MouseClicked(evt);
            }
        });

        jComboBox5.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "1,2,3,4" }));

        jButton8.setText("运行");
        jButton8.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton8MouseClicked(evt);
            }
        });

        jLabel15.setText("jLabel15");

        jLabel16.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N
        jLabel16.setText("时间片大小");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(51, 255, 153));

        jList6.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jScrollPane6.setViewportView(jList6);

        jButton3.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N
        jButton3.setText("优先权调度算法");
        jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton3MouseClicked(evt);
            }
        });

        jList8.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jScrollPane8.setViewportView(jList8);

        jButton4.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jButton4.setText("挂起");
        jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton4MouseClicked(evt);
            }
        });

        jButton6.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jButton6.setText("解挂");
        jButton6.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton6MouseClicked(evt);
            }
        });
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton7.setFont(new java.awt.Font("宋体", 0, 18)); // NOI18N
        jButton7.setText("时间片轮转算法");
        jButton7.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton7MouseClicked(evt);
            }
        });
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jTextField10.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jTextField10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField10ActionPerformed(evt);
            }
        });

        jLabel17.setFont(new java.awt.Font("宋体", 1, 24)); // NOI18N
        jLabel17.setText("就绪队列");

        jLabel18.setFont(new java.awt.Font("宋体", 1, 24)); // NOI18N
        jLabel18.setText("挂起队列");

        jLabel19.setFont(new java.awt.Font("宋体", 1, 24)); // NOI18N
        jLabel19.setText("终止队列");

        jList7.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jScrollPane7.setViewportView(jList7);

        jLabel10.setFont(new java.awt.Font("宋体", 1, 24)); // NOI18N
        jLabel10.setText("后备队列");

        jList5.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jScrollPane5.setViewportView(jList5);

        jLabel11.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jLabel11.setText("进程名");

        jLabel12.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jLabel12.setText("时间");

        jLabel13.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jLabel13.setText("优先级");

        jTextField7.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N

        jTextField8.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N

        jTextField9.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N

        jLabel14.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jLabel14.setText("选择道数");

        jComboBox4.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jComboBox4.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "1", "2", "3" }));
        jComboBox4.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBox4ItemStateChanged(evt);
            }
        });

        jButton2.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jButton2.setText("时间片运转");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton2MouseClicked(evt);
            }
        });
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jLabel1.setText("进程名");
        jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel1MouseClicked(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jLabel2.setText("运行时间");

        jLabel3.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jLabel3.setText("优先权");

        jTextField1.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jTextField1.setText("a");

        jTextField4.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jTextField4.setText("6");

        jComboBox1.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "1", "2", "3", "4", "5", "6" }));
        jComboBox1.setSelectedIndex(3);
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jTextField2.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jTextField2.setText("b");

        jTextField5.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jTextField5.setText("5");

        jComboBox2.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "1", "2", "3", "4", "5", "6" }));
        jComboBox2.setSelectedIndex(5);
        jComboBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox2ActionPerformed(evt);
            }
        });

        jTextField3.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jTextField3.setText("c");
        jTextField3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField3ActionPerformed(evt);
            }
        });

        jTextField6.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jTextField6.setText("4");

        jComboBox3.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jComboBox3.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "1", "2", "3", "4", "5", "6" }));
        jComboBox3.setSelectedIndex(4);

        jButton1.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jButton1.setText("添加进程");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton9.setFont(new java.awt.Font("宋体", 0, 24)); // NOI18N
        jButton9.setText("优先权调度");
        jButton9.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton9MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel17, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 189, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(45, 45, 45)
                                .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jScrollPane8, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(jLabel18, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGap(114, 114, 114)
                                            .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                .addComponent(jScrollPane6, javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(layout.createSequentialGroup()
                                                    .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 189, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addGap(45, 45, 45)
                                                    .addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                            .addComponent(jButton1))
                                        .addGap(8, 8, 8)))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(249, 249, 249)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addGroup(layout.createSequentialGroup()
                                                        .addGap(113, 113, 113)
                                                        .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                                        .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addGap(19, 19, 19)))
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(jLabel13)
                                                    .addComponent(jTextField9, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(230, 230, 230)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 384, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel19, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))))))
                        .addGap(41, 41, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(63, 63, 63)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 91, Short.MAX_VALUE)
                                            .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel2)
                                        .addGap(77, 77, 77)
                                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 334, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(27, 27, 27)
                                .addComponent(jButton9))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel11)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jTextField7, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(18, 18, 18)
                                .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(74, 74, 74))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(81, 81, 81)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(39, 39, 39)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(39, 39, 39)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton2)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(56, 56, 56)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel12)
                            .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addComponent(jLabel17, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(35, 35, 35)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel14))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel18, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel19)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(50, 50, 50))
        );

        pack();
    }// </editor-fold>                        

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {                                      
        // TODO add your handling code here:
        String name=jTextField1.getText();
        String time=jTextField4.getText();
        String rank=jComboBox1.getSelectedItem().toString();
        
        String name1=jTextField2.getText();
        String time1=jTextField5.getText();
        String rank1=jComboBox2.getSelectedItem().toString();
        
        String name2=jTextField3.getText();
        String time2=jTextField6.getText();
        String rank2=jComboBox3.getSelectedItem().toString();
        pcb pcb_1=new pcb(name,time,rank);
        pcb pcb_2=new pcb(name1,time1,rank1);
        pcb pcb_3=new pcb(name2,time2,rank2);
        
        
        pcb_houbei.add(pcb_1);
        pcb_houbei.add(pcb_2);
        pcb_houbei.add(pcb_3);
        int size=pcb_houbei.size();
        String []str=new String[size];
        for(int i=0;i<size;i++)
        {
            str[i]=get_pcb(pcb_houbei.get(i));
        }
       jList5.setListData(str);
       
       
        
    }                                     

    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {                                      
        // TODO add your handling code here:
        int dao_num=Integer.parseInt(jComboBox4.getSelectedItem().toString());
        
        while(dao_num!=0)
        {
            dao_num--;
            if(pcb_houbei.size()>0)
            {
                  pcb_jiuxu.add(pcb_houbei.get(0));
                  pcb_houbei.remove(0);
            }
            else break;
          
        }
       
        
//         String []str=new String[dao_num];
//          for(int i=0;i<dao_num;i++)
//        {
//            str[i]=get_pcb(pcb_jiuxu.get(i));
//        }
          new_genxin();
         
        
        
        
    }                                     

    private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {                                      
        // TODO add your handling code here:
        
        pcb_sort(pcb_jiuxu);//对数组按照指定的办法进行排序
        
        
        pcb p_temp=pcb_jiuxu.get(0);
        pcb_jiuxu.remove(0);
        String name=p_temp.name;
        String rank=p_temp.rank;
        String time=p_temp.time;
        
        int time_to_int=Integer.parseInt(time);
        int rank_to_int=Integer.parseInt(rank);
        
        //使用pcb_ptemp3表示删掉旧的进程pcb
       
        time_to_int--;
        rank_to_int--;
    
        if(time_to_int>0)
        {
              pcb p_temp2=new pcb(name,String.valueOf(time_to_int),String.valueOf( rank_to_int));
               pcb_jiuxu.add( p_temp2);
               
               
              
             
           
             
             int p_size=pcb_jiuxu.size();
             String []str=new String[p_size];
             
             for(int i=0;i<p_size;i++)
             {
               str[i]=get_pcb(pcb_jiuxu.get(i));
             }
             
             
             new_genxin();
             
        }
        else
        {
            //删掉旧的pcb
          
            
            pcb p_temp2=new pcb(name,String.valueOf(time_to_int),String.valueOf(rank_to_int)); 
            pcb_jiuxu.remove(p_temp2);
            pcb_zhongzhi.add(p_temp2);
            new_genxin();
            
//                       int p_size=pcb_zhongzhi.size();
//             String []str=new String[p_size];
//             for(int i=0;i<p_size;i++)
//            {
//                str[i]=get_pcb(pcb_zhongzhi.get(i));
//            }
//            jList7.setListData(str);
        }
       
        
        //设置cpu显示
        jTextField7.setText(name);
        jTextField8.setText(time);
        jTextField9.setText(rank);
        
        
        int select_index=jComboBox4.getSelectedIndex();
       
        while(pcb_jiuxu.size()<select_index&&pcb_houbei.size()>0)
        {
            //如果就绪队列里面的进程数小于规定的道数,且后备队列有进程,则将后备队列调入
            pcb_jiuxu.add(pcb_houbei.get(0));
            
            pcb_houbei.remove(0);
            
        }           
        
        
      
        
        
        
    }                                     

    private void jButton4MouseClicked(java.awt.event.MouseEvent evt) {                                      
        // TODO add your handling code here:
        //先找到要挂起的是哪一个
        int select_index=jList6.getSelectedIndex();
        pcb temp=pcb_jiuxu.get(select_index);
        pcb_jiuxu.remove(select_index);
        //删除在就绪队列中所选中的编号
        
        
        
           pcb_guaqi.add(temp);
           
           //调用这个函数更新界面的显示内容
           new_genxin();
        
    }                                     

    private void jButton5MouseClicked(java.awt.event.MouseEvent evt) {                                      
        // TODO add your handling code here:
        //找到要解挂的进程的编号
         int select_index=jList8.getSelectedIndex();
          pcb temp=pcb_guaqi.get(select_index);
          pcb_guaqi.remove(select_index);
           pcb_jiuxu.add(0, temp);
           
           
            //调用这个函数更新界面的显示内容
           new_genxin();
    }                                     

    private void jComboBox4ItemStateChanged(java.awt.event.ItemEvent evt) {                                            
//         TODO add your handling code here:
        int select_index=Integer.parseInt(jComboBox4.getSelectedItem().toString());
        int num_of_jiuxu=pcb_jiuxu.size();
        while(pcb_jiuxu.size()<select_index&&pcb_houbei.size()>0)
        {
            //如果就绪队列里面的进程数小于规定的道数,且后备队列有进程,则将后备队列调入
            pcb_jiuxu.add(pcb_houbei.get(0));
            pcb_houbei.remove(0);
        }   
    }                                           
    
    private void jButton6MouseClicked(java.awt.event.MouseEvent evt) {                                      
        // TODO add your handling code here:
        int select_index=jList8.getSelectedIndex();
          pcb temp=pcb_guaqi.get(select_index);
          pcb_guaqi.remove(select_index);
           pcb_jiuxu.add(temp);
           
           
            //调用这个函数更新界面的显示内容
           new_genxin();
        
        
    }                                     

    private void jTextField10ActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // TODO add your handling code here:
    }                                            

    private void jButton7MouseClicked(java.awt.event.MouseEvent evt) {                                      
        // TODO add your handling code here:
        int time_stamp=Integer.parseInt(jTextField10.getText());
        
        while(time_stamp!=0)
        {
            time_stamp--;
            pcb p_temp=pcb_jiuxu.get(0);
            jTextField7.setText(p_temp.name);
            jTextField8.setText(p_temp.time);
            jTextField9.setText(p_temp.rank);
            
             int time_to_int=Integer.parseInt(p_temp.time);
             int rank_to_int=Integer.parseInt(p_temp.rank);
        
        //使用pcb_ptemp3表示删掉旧的进程pcb
            pcb_jiuxu.remove(0);
            
            
            time_to_int--;
            rank_to_int--;
            
            
             String temp_name=p_temp.name;
            String temp_time=String.valueOf(time_to_int);
            String temp_rank=String.valueOf(rank_to_int);
            pcb p_add_temp=new pcb(temp_name,temp_time,temp_rank);
            if(time_to_int!=0)
            {
                 pcb_jiuxu.add(p_add_temp);
            }
            else
            {
                pcb_zhongzhi.add(p_add_temp);
            }
            
            
            
           new_genxin();
          
           
            
            
            
            
        }
           
    }                                     

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        
    }                                        

    private void jButton8MouseClicked(java.awt.event.MouseEvent evt) {                                      
        // TODO add your handling code here:
      //没有用的进程
        
    }                                     

    private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // TODO add your handling code here:
    }                                           

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
    }                                        

    private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
    }                                          

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
    }                                        

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
    }                                          

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
    }                                        

    private void jButton9MouseClicked(java.awt.event.MouseEvent evt) {                                      
        // TODO add your handling code here:
        int dao_num=Integer.parseInt(jComboBox4.getSelectedItem().toString());
        System.out.println("点击了优先权运行");
        pcb_sort(pcb_houbei);
        while(dao_num!=0)
        {
            dao_num--;
            if(pcb_houbei.size()>0)
            {
                  pcb_jiuxu.add(pcb_houbei.get(0));
                  pcb_houbei.remove(0);
            }
            else break;
          
        }
          new_genxin();
        
    }                                     

    private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {                                     
        // TODO add your handling code here:
    }                                    
 
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(pcb_demo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(pcb_demo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(pcb_demo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(pcb_demo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
         

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new pcb_demo().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JComboBox<String> jComboBox1;
    private javax.swing.JComboBox<String> jComboBox2;
    private javax.swing.JComboBox<String> jComboBox3;
    private javax.swing.JComboBox<String> jComboBox4;
    private javax.swing.JComboBox<String> jComboBox5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JList<String> jList1;
    private javax.swing.JList<String> jList2;
    private javax.swing.JList<String> jList3;
    private javax.swing.JList<String> jList4;
    private javax.swing.JList<String> jList5;
    private javax.swing.JList<String> jList6;
    private javax.swing.JList<String> jList7;
    private javax.swing.JList<String> jList8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField10;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JTextField jTextField8;
    private javax.swing.JTextField jTextField9;
    // End of variables declaration                   
}

六、实验结论
  处理机调度采用优先级调度算法比较灵活、科学,可防止有些进程一直得不到调度,也可防止有些进程长期垄断处理机。但是不足的是需要花费相当多的执行程序时间,因而花费的系统开销比较大。

七、实验小结

  1. 写程序前先要理清楚思路,想好项的大体框架,比如本实验我写的一个new_genxin()函数只要在每一次点击按钮之后调用一次函数,就可以实现容器的显示 更新,这样可以大大的提高代码的复用性
  2. 通过本实验我对处理机调度的了解也是加深了一步,对整个过程是如何进行的也是更加熟悉,在实践中融合理解了书本知识。
  3. 需要熟练使用一些好用的api方便编程。

标签:操作系统,GroupLayout,实验,swing,pcb,new,javax,SIZE
来源: https://blog.csdn.net/hehehehejiejie/article/details/109635228