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

📄 systemmain.java

📁 操作系统进程调度算法java实现
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    void CtrlIo(Vector v){//使阻碍进程入等待队列
     
     ctrl.goTOWaitQueue(v);
 
    }
  
   
    ActionListener bb=new ActionListener(){//点击运行后开始监听所有动作
     public void actionPerformed(ActionEvent e){
      
      if(e.getSource()==Start){
       if(e.getActionCommand().equals("Start"))
       {
        Complete.removeAll();
        ctrl.CompleteQueue.clear();
        time.start();
        Start.setText("Stop");
       }
       if(e.getActionCommand().equals("Stop"))
       {
        time.stop();
        Start.setText("Start");
       }
       
      }
      else if(e.getSource()==time){
       Vector v=new Vector(20);
       String all="";
       
       while(Io()==false);//若IO端口无空 则一直等待,防止所有进程都人了等待队列,导致就绪队列为空,而直接跳出程序
       
       
             if(ctrl.ifCanSchedule()==false) { //看等待队列是否为空,若为空退出
                 WaitRun.removeAll();
                 Wait.removeAll();
                
              Start.setText("Start");
              Run.setText("");
              JScrollPane b1=new JScrollPane(ctrl.getWaitRun());
           WaitRun.add(b1);
           JScrollPane b2=new JScrollPane(ctrl.getWait());
           Wait.add(b2);Start.setText("Stop");
    Start.setText("Start"); time.stop();return;
    }
            
            
             slow();
            
             //FirstDo算法
             if(temp.equals(FirstDo)){v=ctrl.schedule(1);if(Io()==false) CtrlIo(v);else ctrl.CompleteQueue.add(v);}//若IO无空入等待队列
             //ShortWorkDo算法
             if(temp.equals(ShortWorkDo)) {v=ctrl.schedule(2);if(Io()==false) CtrlIo(v);else ctrl.CompleteQueue.add(v);}//完成后入完成队列
             //StaticPriority算法
             if(temp.equals(HighPriorityDo)) {v=ctrl.schedule(3);if(Io()==false) CtrlIo(v);else ctrl.CompleteQueue.add(v);}
             if(temp.equals(DivideTime)) {v=ctrl.schedule(4);if(Io()==false) CtrlIo(v);else if(ctrl.DivideTemp==1) ctrl.CompleteQueue.add(v);}
             //if(temp.equals(DivideAndHighPriority)) v=ctrl.schedule(5);
             String aa="运行队列ID:"+v.get(0);
             String bb="进程优先级:"+v.get(1);
             String cc="进程时间片:"+v.get(2);
             String dd="进程消耗时间:"+v.get(3);
             all="<html>"+aa+"<br>"+bb+"<br>"+cc+"<br>"+dd+"<br>"+"</html>";
          
           
             WaitRun.removeAll();
             Wait.removeAll();
             Complete.removeAll();
              Start.setText("Start");
              Run.setText(all);
        JScrollPane b1=new JScrollPane(ctrl.getWaitRun());
        WaitRun.add(b1);
        JScrollPane b2=new JScrollPane(ctrl.getWait());
        Wait.add(b2);
        JScrollPane b3=new JScrollPane(ctrl.getComplete());
        Complete.add(b3);
        Start.setText("Stop");
       

      }
     }
    };

    ItemListener iolistener=new ItemListener(){
     public void itemStateChanged(ItemEvent e){

      if(((String)e.getItem()).equals("允许IO堵塞"))
       noio=0;
      else
       noio=1;

     
     }
     
    };
   
   
    ActionListener pri=new ActionListener(){//动态修改优先级别
     public void actionPerformed(ActionEvent e){
      JFrame hand=new JFrame();
      JPanel pane=new JPanel();
      final JTextField id=new JTextField();
      final JTextField pri=new JTextField();
      JButton set=new JButton();
      JLabel label1=new JLabel();
      label1.setText("进程ID");
      JLabel label2=new JLabel();
      label2.setText("优先级");
      set.setText("修改优先级");
            set.addActionListener(new java.awt.event.ActionListener() {//对修改进行监听
                public void actionPerformed(java.awt.event.ActionEvent e) {
                 int ID=Integer.parseInt((String)id.getText());
                 int PRI=Integer.parseInt((String)pri.getText());
                 Vector vv=new Vector();
                 for(int i=0;i<ctrl.WaitRunQueue.size();i++)
                 {
                  vv=(Vector)ctrl.WaitRunQueue.get(i);
                  if(vv.get(0).equals(new Integer(ID)))
                  {
                   vv.set(1,new Integer(PRI));
                   vv.set(2,new Integer(PRI));
                 
                   ctrl.WaitRunQueue.set(i,vv);
                  }

                 }
                 
                 
                 JTable table=new JTable();
            
                 Start.setText("");
                 table=ctrl.getWaitRun();

                 WaitRun.removeAll();
                 WaitRun.add(new JScrollPane(table));
                 Start.setText("Start");
 
                }
            });
           
           
           
            pane.setLayout(new java.awt.GridLayout(3,2));
            pane.add(label1);
            pane.add(id);
            pane.add(label2);
            pane.add(pri);
            pane.add(set);
            hand.getContentPane().add(pane);
            hand.pack();
            hand.setSize(300,300);
            hand.setVisible(true);
      
      
     }
     
    };
   

 

   
   
    JRadioButton temp=new JRadioButton();//处理单选钮
    ActionListener ae = new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            JRadioButton radio = (JRadioButton) ae.getSource();
            temp=radio;
     
        }
    };
 
   
    /**
     *创建一个新进程
     */
   
    private void HandProcessActionPerformed(java.awt.event.ActionEvent evt) {
JFrame hand=new JFrame();
final JTextField Priority=new JTextField();
final JTextField ConsultTime=new JTextField();
JTextField other=new JTextField();
JPanel pane=new JPanel();
JButton set=new JButton();
JLabel label1=new JLabel();
label1.setText("优先权");
JLabel label2=new JLabel();
label2.setText("程序消耗时间");
JLabel label3=new JLabel();
label3.setText("其他");

set.setText("创建");
        set.addActionListener(new java.awt.event.ActionListener() {//对创建进行监听
            public void actionPerformed(java.awt.event.ActionEvent e) {
              JTable table;
              Start.setText("");
                table=ctrl.createAProcess(Integer.parseInt(Priority.getText()), Integer.parseInt(ConsultTime.getText()));
                WaitRun.removeAll();
                WaitRun.add(new JScrollPane(table));
                Start.setText("Start");
            }
        });
hand.setTitle("设置进程初始参数");
pane.setLayout(new java.awt.GridLayout(4,2));
pane.add(Priority);
pane.add(label1);
pane.add(ConsultTime);
pane.add(label2);
pane.add(other);
pane.add(label3);
pane.add(set);
hand.getContentPane().add(pane);


hand.pack();
hand.setSize(300,300);
hand.setVisible(true);
hand.show();
    }

   

   

   
   
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SystemMain().setVisible(true);
               
            }
        });
    }
   
    // 变量声明 - 不进行修改
    private javax.swing.JPanel Complete;
    private javax.swing.JRadioButton DivideAndHighPriority;
    private javax.swing.JRadioButton DivideTime;
    private javax.swing.JButton DynamicModifyPriority;
    private javax.swing.JRadioButton FirstDo;
    private javax.swing.JButton HandProcess;
    private javax.swing.JRadioButton HighPriorityDo;
    private javax.swing.JButton RandomProcess;
    private javax.swing.JLabel Run;
    private javax.swing.JRadioButton ShortWorkDo;
    private javax.swing.JButton Start;
    private javax.swing.JPanel Wait;
    private javax.swing.JPanel WaitRun;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.Timer time;
    private JComboBox ifio;
    private int noio=1;
    // 变量声明结束
}


      
   
            

⌨️ 快捷键说明

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