package com.zzu.os; import java.text.SimpleDateFormat; import java.util.Date; import javax.swing.JComboBox; @SuppressWarnings("serial") public class MyJFrame extends javax.swing.JFrame { //算法名字列表 private javax.swing.JComboBox chooseNameComboBox; //选择算法名字的提示框 private javax.swing.JLabel chooseNameLable; //选择物理块个数的列表 private javax.swing.JComboBox chooseNumberComboBox; private javax.swing.JComboBox timeComboBox; //被淘汰的页面× private java.awt.Label error1; private java.awt.Label error2; private java.awt.Label error3; private java.awt.Label error4; private java.awt.Label error5; private java.awt.Label error6; private java.awt.Label error7; private java.awt.Label error8; //错误提示框 private javax.swing.JLabel errorMessage; //标题标签 private javax.swing.JLabel jLabel1; private javax.swing.JLabel timeLabel; //内存页面的置换(详细情况) private java.awt.TextArea messageTextArea; //存放页面的物理块 private java.awt.Label number1; private java.awt.Label number2; private java.awt.Label number3; private java.awt.Label number4; private java.awt.Label number5; private java.awt.Label number6; private java.awt.Label number7; private java.awt.Label number8; //提示输入页面序列的标签 private javax.swing.JLabel queueLabel; //输入页面序列的文本框 private javax.swing.JTextField queueTextFiled; //产生中断请求的页面√ private java.awt.Label right1; private java.awt.Label right2; private java.awt.Label right3; private java.awt.Label right4; private java.awt.Label right5; private java.awt.Label right6; private java.awt.Label right7; private java.awt.Label right8; //开始模拟的按钮 private javax.swing.JButton startButton; private javax.swing.JLabel tipLabel; private javax.swing.JLabel titleLabel; public MyJFrame() { initComponents(); } private void initComponents() { titleLabel = new javax.swing.JLabel(); queueLabel = new javax.swing.JLabel(); queueTextFiled = new javax.swing.JTextField(); chooseNameLable = new javax.swing.JLabel(); chooseNameComboBox = new javax.swing.JComboBox(); jLabel1 = new javax.swing.JLabel(); chooseNumberComboBox = new javax.swing.JComboBox(); startButton = new javax.swing.JButton(); tipLabel = new javax.swing.JLabel(); errorMessage = new javax.swing.JLabel(); messageTextArea = new java.awt.TextArea(); number1 = new java.awt.Label(); error1 = new java.awt.Label(); right1 = new java.awt.Label(); number2 = new java.awt.Label(); number3 = new java.awt.Label(); number4 = new java.awt.Label(); number5 = new java.awt.Label(); number6 = new java.awt.Label(); number7 = new java.awt.Label(); number8 = new java.awt.Label(); right2 = new java.awt.Label(); error2 = new java.awt.Label(); right3 = new java.awt.Label(); error3 = new java.awt.Label(); right4 = new java.awt.Label(); error4 = new java.awt.Label(); right5 = new java.awt.Label(); error5 = new java.awt.Label(); right6 = new java.awt.Label(); error6 = new java.awt.Label(); right7 = new java.awt.Label(); error7 = new java.awt.Label(); right8 = new java.awt.Label(); error8 = new java.awt.Label(); timeLabel = new javax.swing.JLabel(); timeComboBox = new javax.swing.JComboBox(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("页面置换算法模拟系统"); setResizable(false); titleLabel.setBackground(new java.awt.Color(102, 102, 102)); titleLabel.setFont(new java.awt.Font("宋体", 1, 24)); // NOI18N titleLabel.setForeground(new java.awt.Color(0, 0, 153)); titleLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); titleLabel.setText("欢迎进入页面置换算法模拟系统"); titleLabel.setToolTipText("Welcome Title"); queueLabel.setBackground(new java.awt.Color(0, 204, 51)); queueLabel.setFont(new java.awt.Font("宋体", 1, 14)); // NOI18N queueLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); queueLabel.setLabelFor(titleLabel); queueLabel.setText("请您输入要进入内存的页面序列(各页面用空格分割并且各页面号为非负整数):"); queueLabel.setToolTipText("请输入非负整数"); queueTextFiled.setToolTipText("请您输入非负整数且用空格分割开"); chooseNameLable.setFont(new java.awt.Font("宋体", 1, 14)); // NOI18N chooseNameLable.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); chooseNameLable.setText("请选择要模拟的算法名称:"); chooseNameComboBox.setFont(new java.awt.Font("宋体", 0, 14)); // NOI18N chooseNameComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Optimal", "FIFO", "LRU", "NRU", "改进Clock" })); chooseNameComboBox.setToolTipText("请选择"); chooseNameComboBox.setAutoscrolls(true); jLabel1.setFont(new java.awt.Font("宋体", 1, 14)); // NOI18N jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel1.setText("请选择物理块的个数:"); chooseNumberComboBox.setFont(new java.awt.Font("宋体", 0, 14)); // NOI18N chooseNumberComboBox.setMaximumRowCount(10); chooseNumberComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2", "3", "4", "5", "6", "7", "8" })); chooseNumberComboBox.setToolTipText("请选择"); chooseNumberComboBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { chooseNumberComboBoxActionPerformed(evt); } }); startButton.setFont(new java.awt.Font("宋体", 1, 14)); // NOI18N startButton.setText("开始模拟"); startButton.setToolTipText("请单击"); startButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { try { startButtonActionPerformed(evt); } catch (InterruptedException e) { e.printStackTrace(); } } }); tipLabel.setFont(new java.awt.Font("宋体", 1, 14)); // NOI18N tipLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); tipLabel.setText("运行结果:"); errorMessage.setFont(new java.awt.Font("宋体", 1, 14)); // NOI18N errorMessage.setForeground(new java.awt.Color(255, 0, 0)); number1.setAlignment(java.awt.Label.CENTER); number1.setBackground(new java.awt.Color(204, 0, 0)); number1.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N number1.setName("number1"); // NOI18N error1.setAlignment(java.awt.Label.CENTER); error1.setBackground(new java.awt.Color(204, 204, 0)); right1.setAlignment(java.awt.Label.CENTER); right1.setBackground(new java.awt.Color(204, 204, 0)); number2.setAlignment(java.awt.Label.CENTER); number2.setBackground(new java.awt.Color(204, 0, 0)); number2.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N number2.setName("number1"); // NOI18N number3.setAlignment(java.awt.Label.CENTER); number3.setBackground(new java.awt.Color(204, 0, 0)); number3.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N number3.setName("number1"); // NOI18N number4.setAlignment(java.awt.Label.CENTER); number4.setBackground(new java.awt.Color(204, 0, 0)); number4.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N number4.setName("number1"); // NOI18N number5.setAlignment(java.awt.Label.CENTER); number5.setBackground(new java.awt.Color(204, 0, 0)); number5.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N number5.setName("number1"); // NOI18N number6.setAlignment(java.awt.Label.CENTER); number6.setBackground(new java.awt.Color(204, 0, 0)); number6.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N number6.setName("number1"); // NOI18N number7.setAlignment(java.awt.Label.CENTER); number7.setBackground(new java.awt.Color(204, 0, 0)); number7.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N number7.setName("number1"); // NOI18N number8.setAlignment(java.awt.Label.CENTER); number8.setBackground(new java.awt.Color(204, 0, 0)); number8.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N number8.setName("number1"); // NOI18N right2.setAlignment(java.awt.Label.CENTER); right2.setBackground(new java.awt.Color(204, 204, 0)); error2.setAlignment(java.awt.Label.CENTER); error2.setBackground(new java.awt.Color(204, 204, 0)); right3.setAlignment(java.awt.Label.CENTER); right3.setBackground(new java.awt.Color(204, 204, 0)); error3.setAlignment(java.awt.Label.CENTER); error3.setBackground(new java.awt.Color(204, 204, 0)); right4.setAlignment(java.awt.Label.CENTER); right4.setBackground(new java.awt.Color(204, 204, 0)); error4.setAlignment(java.awt.Label.CENTER); error4.setBackground(new java.awt.Color(204, 204, 0)); right5.setAlignment(java.awt.Label.CENTER); right5.setBackground(new java.awt.Color(204, 204, 0)); error5.setAlignment(java.awt.Label.CENTER); error5.setBackground(new java.awt.Color(204, 204, 0)); right6.setAlignment(java.awt.Label.CENTER); right6.setBackground(new java.awt.Color(204, 204, 0)); error6.setAlignment(java.awt.Label.CENTER); error6.setBackground(new java.awt.Color(204, 204, 0)); right7.setAlignment(java.awt.Label.CENTER); right7.setBackground(new java.awt.Color(204, 204, 0)); error7.setAlignment(java.awt.Label.CENTER); error7.setBackground(new java.awt.Color(204, 204, 0)); right8.setAlignment(java.awt.Label.CENTER); right8.setBackground(new java.awt.Color(204, 204, 0)); error8.setAlignment(java.awt.Label.CENTER); error8.setBackground(new java.awt.Color(204, 204, 0)); timeLabel.setFont(new java.awt.Font("宋体", 1, 14)); // NOI18N timeLabel.setText("请选择运行延迟的时间(单位:秒):"); timeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5" })); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(125, 125, 125) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(tipLabel) .addGroup(layout.createSequentialGroup() .addComponent(number2, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(right2, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(error2, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(number3, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(right3, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(error3, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(number4, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(right4, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(error4, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(number5, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(right5, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(error5, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(number6, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(right6, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(error6, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(number7, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(right7, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(error7, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(number8, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(error8, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(right8, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(number1, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(right1, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(error1, javax.swing.GroupLayout.PREFERRED_SIZE, 46, 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(messageTextArea, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 710, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(startButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addComponent(chooseNameLable) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(chooseNameComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(timeLabel)) .addComponent(queueLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 693, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(queueTextFiled, javax.swing.GroupLayout.PREFERRED_SIZE, 407, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(errorMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 347, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(layout.createSequentialGroup() .addComponent(timeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(chooseNumberComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))))) .addGap(126, 126, 126)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addComponent(titleLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 495, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(319, 319, 319)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(71, 71, 71) .addComponent(titleLabel) .addGap(42, 42, 42) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(chooseNameLable) .addComponent(chooseNameComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(chooseNumberComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(timeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(timeLabel))) .addGap(23, 23, 23) .addComponent(errorMessage) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(queueLabel) .addComponent(queueTextFiled, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(14, 14, 14) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(startButton, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(tipLabel, javax.swing.GroupLayout.Alignment.TRAILING)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(right1, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(error1, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(number1, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(5, 5, 5) .addComponent(number2, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(error2, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addComponent(right2, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(5, 5, 5) .addComponent(number3, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(error3, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addComponent(right3, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(5, 5, 5) .addComponent(number4, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(error4, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addComponent(right4, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(5, 5, 5) .addComponent(number5, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(error5, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addComponent(right5, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(5, 5, 5) .addComponent(number6, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(error6, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addComponent(right6, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(5, 5, 5) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(number7, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(right7, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(error7, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(5, 5, 5) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(number8, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(error8, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(right8, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))) .addComponent(messageTextArea, javax.swing.GroupLayout.PREFERRED_SIZE, 387, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(73, 73, 73)) ); pack(); } private void startButtonActionPerformed(java.awt.event.ActionEvent evt) throws InterruptedException { number1.setText(""); number2.setText(""); number3.setText(""); number4.setText(""); number5.setText(""); number6.setText(""); number7.setText(""); number8.setText(""); error1.setText(""); error2.setText(""); error3.setText(""); error4.setText(""); error5.setText(""); error6.setText(""); error7.setText(""); error8.setText(""); right1.setText(""); right2.setText(""); right3.setText(""); right4.setText(""); right5.setText(""); right6.setText(""); right7.setText(""); right8.setText(""); messageTextArea.setText(""); errorMessage.setText(""); // 获取页面号序列 String orderList = this.queueTextFiled.getText(); // 用空格进行分割 String temp[] = orderList.split(" "); // 将分割后的页面号存放在数组 int page[] = new int[temp.length]; for (int i = 0; i < page.length; i++) { try { page[i] = Integer.parseInt(temp[i]); } catch (Exception ex) { this.errorMessage.setText("装入内存的页面号输入错误,请重新输入。"); this.queueTextFiled.setText(""); return; } } // 获得测试的算法名 String operateName = this.chooseNameComboBox.getSelectedItem() .toString(); // 获得物理块的数量 int num = Integer.parseInt(this.chooseNumberComboBox.getSelectedItem() .toString()); int sleepTime = Integer.parseInt(this.timeComboBox.getSelectedItem() .toString()); sleepTime = sleepTime * 1000; // 根据算法名运行相应的方法 if (operateName.equals("Optimal")) { Optimal(page, num,sleepTime); } else if (operateName.equals("FIFO")) { FIFO(page, num,sleepTime); } else if (operateName.equals("LRU")) { LRU(page, num,sleepTime); } else if (operateName.equals("NRU")) { NRU(page, num,sleepTime); } else { betterNRU(page, num, sleepTime); } } private void chooseNumberComboBoxActionPerformed( java.awt.event.ActionEvent evt) { JComboBox temp = (JComboBox) (evt.getSource()); int num = temp.getSelectedIndex(); switch (num) { case 0: number1.setVisible(true); number2.setVisible(true); number3.setVisible(false); number4.setVisible(false); number5.setVisible(false); number6.setVisible(false); number7.setVisible(false); number8.setVisible(false); number8.setVisible(false); right1.setVisible(true); right2.setVisible(true); right3.setVisible(false); right4.setVisible(false); right5.setVisible(false); right6.setVisible(false); right7.setVisible(false); right8.setVisible(false); error1.setVisible(true); error2.setVisible(true); error3.setVisible(false); error4.setVisible(false); error5.setVisible(false); error6.setVisible(false); error7.setVisible(false); error8.setVisible(false); break; case 1: number1.setVisible(true); number2.setVisible(true); number3.setVisible(true); number4.setVisible(false); number5.setVisible(false); number6.setVisible(false); number7.setVisible(false); number8.setVisible(false); number8.setVisible(false); right1.setVisible(true); right2.setVisible(true); right3.setVisible(true); right4.setVisible(false); right5.setVisible(false); right6.setVisible(false); right7.setVisible(false); right8.setVisible(false); error1.setVisible(true); error2.setVisible(true); error3.setVisible(true); error4.setVisible(false); error5.setVisible(false); error6.setVisible(false); error7.setVisible(false); error8.setVisible(false); break; case 2: number1.setVisible(true); number2.setVisible(true); number3.setVisible(true); number4.setVisible(true); number5.setVisible(false); number6.setVisible(false); number7.setVisible(false); number8.setVisible(false); number8.setVisible(false); right1.setVisible(true); right2.setVisible(true); right3.setVisible(true); right4.setVisible(true); right5.setVisible(false); right6.setVisible(false); right7.setVisible(false); right8.setVisible(false); error1.setVisible(true); error2.setVisible(true); error3.setVisible(true); error4.setVisible(true); error5.setVisible(false); error6.setVisible(false); error7.setVisible(false); error8.setVisible(false); break; case 3: number1.setVisible(true); number2.setVisible(true); number3.setVisible(true); number4.setVisible(true); number5.setVisible(true); number6.setVisible(false); number7.setVisible(false); number8.setVisible(false); number8.setVisible(false); right1.setVisible(true); right2.setVisible(true); right3.setVisible(true); right4.setVisible(true); right5.setVisible(true); right6.setVisible(false); right7.setVisible(false); right8.setVisible(false); error1.setVisible(true); error2.setVisible(true); error3.setVisible(true); error4.setVisible(true); error5.setVisible(true); error6.setVisible(false); error7.setVisible(false); error8.setVisible(false); break; case 4: number1.setVisible(true); number2.setVisible(true); number3.setVisible(true); number4.setVisible(true); number5.setVisible(true); number6.setVisible(true); number7.setVisible(false); number8.setVisible(false); number8.setVisible(false); right1.setVisible(true); right2.setVisible(true); right3.setVisible(true); right4.setVisible(true); right5.setVisible(true); right6.setVisible(true); right7.setVisible(false); right8.setVisible(false); error1.setVisible(true); error2.setVisible(true); error3.setVisible(true); error4.setVisible(true); error5.setVisible(true); error6.setVisible(true); error7.setVisible(false); error8.setVisible(false); break; case 5: number1.setVisible(true); number2.setVisible(true); number3.setVisible(true); number4.setVisible(true); number5.setVisible(true); number6.setVisible(true); number7.setVisible(true); number8.setVisible(true); number8.setVisible(false); right1.setVisible(true); right2.setVisible(true); right3.setVisible(true); right4.setVisible(true); right5.setVisible(true); right6.setVisible(true); right7.setVisible(true); right8.setVisible(false); error1.setVisible(true); error2.setVisible(true); error3.setVisible(true); error4.setVisible(true); error5.setVisible(true); error6.setVisible(true); error7.setVisible(true); error8.setVisible(false); break; default: number1.setVisible(true); number2.setVisible(true); number3.setVisible(true); number4.setVisible(true); number5.setVisible(true); number6.setVisible(true); number7.setVisible(true); number8.setVisible(true); number8.setVisible(true); right1.setVisible(true); right2.setVisible(true); right3.setVisible(true); right4.setVisible(true); right5.setVisible(true); right6.setVisible(true); right7.setVisible(true); right8.setVisible(true); error1.setVisible(true); error2.setVisible(true); error3.setVisible(true); error4.setVisible(true); error5.setVisible(true); error6.setVisible(true); error7.setVisible(true); error8.setVisible(true); break; } } // 将数组转化为以[ , , , ]的格式字符串 public String outPut(int n[]) { String str = ""; for (int i = 0; i < n.length; i++) { if (i == 0) { str += "[" + n[i] + ","; } else if (i == n.length - 1) { str += n[i] + "]"; } else { str += n[i] + ","; } } return str; } //将√和×全部清空 public void setNull() { right1.setText(""); right2.setText(""); right3.setText(""); right4.setText(""); right5.setText(""); right6.setText(""); right7.setText(""); right8.setText(""); error1.setText(""); error2.setText(""); error3.setText(""); error4.setText(""); error5.setText(""); error6.setText(""); error7.setText(""); error8.setText(""); } // LRU测试算法的模拟 public void LRU(int n[], int num, int sleepTime) throws InterruptedException { // 用于存放进入内存的页面 int temp[] = new int[num]; // 始终与内存中的页面顺序保持一致 int temp_t[] = new int[num]; // 初始内存中页面都为-1,即-1代表内存中的该位置为空 for (int i = 0; i < temp.length; i++) { temp[i] = -1; temp_t[i] = -1; } // 缺页中断的次数 int line = 0; int line_t = 0; for (int i = 0; i < n.length; i++) { boolean b = true; // 判断一下内存中是否有将要装入内存的页面 for (int j = 0; j < temp.length; j++) { if (n[i] == temp[j]) { b = false; break; } } // 如果没有 if (b) { // 当物理块没有装满时,依次将要装入的页面装入内存 if (line < num) { temp[line++] = n[i]; temp_t[line_t++] = n[i]; messageTextArea.append(new SimpleDateFormat( "yyyy-MM-dd hh:mm:ss").format(new Date()) + ": " + n[i] + "号页被装入内存,物理块的结果为: " + outPut(temp_t)); messageTextArea.append("\n"); Thread.sleep(sleepTime); setNull(); switch (line) { case 1: right1.setText("√"); Thread.sleep(sleepTime); number1.setText(n[i] + ""); break; case 2: right2.setText("√"); Thread.sleep(sleepTime); number2.setText(n[i] + ""); break; case 3: right3.setText("√"); Thread.sleep(sleepTime); number3.setText(n[i] + ""); break; case 4: right4.setText("√"); Thread.sleep(sleepTime); number4.setText(n[i] + ""); break; case 5: right5.setText("√"); Thread.sleep(sleepTime); number5.setText(n[i] + ""); break; case 6: right6.setText("√"); Thread.sleep(sleepTime); number6.setText(n[i] + ""); break; case 7: setNull(); right7.setText("√"); Thread.sleep(sleepTime); number7.setText(n[i] + ""); break; case 8: right8.setText("√"); Thread.sleep(sleepTime); number8.setText(n[i] + ""); break; } Thread.sleep(sleepTime); } // 否则的话:淘汰未来不会再使用或者最久被使用的页面 else { //将最长时间未被使用的页面号保存下来 int temp_1 = temp[0]; //将数组向前挪一个位置 for (int j = 1; j < temp.length; j++) { temp[j - 1] = temp[j]; } //将页面放到最后一个位置 temp[temp.length - 1] = n[i]; int k = 0; //在内存中找到要淘汰页面的位置 for (int j = 0; j < temp_t.length; j++) { if (temp_t[j] == temp_1) { temp_t[j] = n[i]; k = j + 1; break; } } messageTextArea.append(new SimpleDateFormat( "yyyy-MM-dd hh:mm:ss").format(new Date()) + ": " + n[i] + "号页被装入内存," + temp_1 + "号页被换出,物理块的结果为: " + outPut(temp_t)); messageTextArea.append("\n"); setNull(); switch (k) { case 1: error1.setText("×"); Thread.sleep(sleepTime); right1.setText("√"); Thread.sleep(sleepTime); number1.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 2: error2.setText("×"); Thread.sleep(sleepTime); right2.setText("√"); Thread.sleep(sleepTime); number2.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 3: error3.setText("×"); Thread.sleep(sleepTime); right3.setText("√"); Thread.sleep(sleepTime); number3.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 4: error4.setText("×"); Thread.sleep(sleepTime); right4.setText("√"); Thread.sleep(sleepTime); number4.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 5: error5.setText("×"); Thread.sleep(sleepTime); right5.setText("√"); Thread.sleep(sleepTime); number5.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 6: setNull(); error6.setText("×"); Thread.sleep(sleepTime); right6.setText("√"); Thread.sleep(sleepTime); number6.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 7: setNull(); error7.setText("×"); Thread.sleep(sleepTime); right7.setText("√"); Thread.sleep(sleepTime); number7.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 8: error8.setText("×"); Thread.sleep(sleepTime); right8.setText("√"); Thread.sleep(sleepTime); number8.setText(n[i] + ""); Thread.sleep(sleepTime); break; } line++; } } // 如果要装入内存中的页面,内存中已存在 else { //改变一下页面序列(以使用时间长度排序) for (int j = 0; j < temp.length; j++) { if (temp[j] == n[i]) { for (int j2 = j; j2 < temp.length - 1; j2++) { temp[j2] = temp[j2 + 1]; } temp[temp.length - 1] = n[i]; } } messageTextArea.append(new SimpleDateFormat( "yyyy-MM-dd hh:mm:ss").format(new Date()) + ": " + n[i] + "号页已在内存,物理块的结果为: " + outPut(temp_t)); messageTextArea.append("\n"); Thread.sleep(sleepTime); } } double number = line; double sum = n.length; //计算出页面中断的次数、页面个数和缺页中断率。 messageTextArea.append("缺页中断次数:" + line + ", 页面序列的总长度:" + n.length + ", 缺页中断率:" + number / sum * 100 + "%"); } // FIFO测试算法的模拟 public void FIFO(int n[], int num, int sleepTime) throws InterruptedException { // 存放内存中页面 int temp[] = new int[num]; int temp_t[] = new int[num]; // 初始另内存中页面都为-1,即-1代表内存中的该位置为空 for (int i = 0; i < temp.length; i++) { temp[i] = -1; temp_t[i] = -1; } // 缺页中断的次数 int line = 0; int line_t = 0; for (int i = 0; i < n.length; i++) { boolean b = true; // 判断一下内存中是否有将要装入内存的页面 for (int j = 0; j < temp.length; j++) { if (n[i] == temp[j]) { b = false; break; } } // 如果没有 if (b) { // 当物理块没有装满时,依次将要装入的页面装入内存 if (line < num) { temp[line++] = n[i]; temp_t[line_t++] = n[i]; messageTextArea.append(new SimpleDateFormat( "yyyy-MM-dd hh:mm:ss").format(new Date()) + ": " + n[i] + "号页被装入内存,物理块的结果为: " + outPut(temp_t)); messageTextArea.append("\n"); Thread.sleep(sleepTime); setNull(); switch (line) { case 1: right1.setText("√"); Thread.sleep(sleepTime); number1.setText(n[i] + ""); break; case 2: right2.setText("√"); Thread.sleep(sleepTime); number2.setText(n[i] + ""); break; case 3: right3.setText("√"); Thread.sleep(sleepTime); number3.setText(n[i] + ""); break; case 4: right4.setText("√"); Thread.sleep(sleepTime); number4.setText(n[i] + ""); break; case 5: right5.setText("√"); Thread.sleep(sleepTime); number5.setText(n[i] + ""); break; case 6: right6.setText("√"); Thread.sleep(sleepTime); number6.setText(n[i] + ""); break; case 7: setNull(); right7.setText("√"); Thread.sleep(sleepTime); number7.setText(n[i] + ""); break; case 8: right8.setText("√"); Thread.sleep(sleepTime); number8.setText(n[i] + ""); break; } Thread.sleep(sleepTime); } // 否则的话:淘汰未来不会再使用或者最久被使用的页面 else { int temp_1 = temp[0]; for (int j = 1; j < temp.length; j++) { temp[j - 1] = temp[j]; } temp[temp.length - 1] = n[i]; int k = 0; for (int j = 0; j < temp_t.length; j++) { if (temp_t[j] == temp_1) { temp_t[j] = n[i]; k = j + 1; } } messageTextArea.append(new SimpleDateFormat( "yyyy-MM-dd hh:mm:ss").format(new Date()) + ": " + n[i] + "号页被装入内存," + temp_1 + "号页被换出,物理块的结果为: " + outPut(temp_t)); messageTextArea.append("\n"); setNull(); switch (k) { case 1: error1.setText("×"); Thread.sleep(sleepTime); right1.setText("√"); Thread.sleep(sleepTime); number1.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 2: error2.setText("×"); Thread.sleep(sleepTime); right2.setText("√"); Thread.sleep(sleepTime); number2.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 3: error3.setText("×"); Thread.sleep(sleepTime); right3.setText("√"); Thread.sleep(sleepTime); number3.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 4: error4.setText("×"); Thread.sleep(sleepTime); right4.setText("√"); Thread.sleep(sleepTime); number4.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 5: error5.setText("×"); Thread.sleep(sleepTime); right5.setText("√"); Thread.sleep(sleepTime); number5.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 6: setNull(); error6.setText("×"); Thread.sleep(sleepTime); right6.setText("√"); Thread.sleep(sleepTime); number6.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 7: setNull(); error7.setText("×"); Thread.sleep(sleepTime); right7.setText("√"); Thread.sleep(sleepTime); number7.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 8: error8.setText("×"); Thread.sleep(sleepTime); right8.setText("√"); Thread.sleep(sleepTime); number8.setText(n[i] + ""); Thread.sleep(sleepTime); break; } line++; } } // 如果要装入内存中的页面,内存中已存在 else { messageTextArea.append(new SimpleDateFormat( "yyyy-MM-dd hh:mm:ss").format(new Date()) + ": " + n[i] + "号页已在内存,物理块的结果为: " + outPut(temp_t)); messageTextArea.append("\n"); Thread.sleep(sleepTime); } } double number = line; double sum = n.length; messageTextArea.append("缺页中断次数:" + line + ", 页面序列的总长度:" + n.length + ", 缺页中断率:" + number / sum * 100 + "%"); } // Optimal测试算法的模拟 public void Optimal(int n[], int num, int sleepTime) throws InterruptedException { //存放内存中页面 int temp[] = new int[num]; //初始另内存中页面都为-1,即-1代表内存中的该位置为空 for (int i = 0; i < temp.length; i++) { temp[i] = -1; } int line = 0; for (int i = 0; i < n.length; i++) { boolean b = true; //判断一下内存中是否有将要装入内存的页面 for (int j = 0; j < temp.length; j++) { if (n[i] == temp[j]) { b = false; break; } } //如果没有 if (b) { //当物理块没有装满时,依次将要装入的页面装入内存 if (line < num) { temp[line++] = n[i]; messageTextArea.append(new SimpleDateFormat( "yyyy-MM-dd hh:mm:ss").format(new Date()) + ": " + n[i] + "号页被装入内存,物理块的结果为: " + outPut(temp)); messageTextArea.append("\n"); Thread.sleep(sleepTime); setNull(); switch (line) { case 1: right1.setText("√"); Thread.sleep(sleepTime); number1.setText(n[i] + ""); break; case 2: right2.setText("√"); Thread.sleep(sleepTime); number2.setText(n[i] + ""); break; case 3: right3.setText("√"); Thread.sleep(sleepTime); number3.setText(n[i] + ""); break; case 4: right4.setText("√"); Thread.sleep(sleepTime); number4.setText(n[i] + ""); break; case 5: right5.setText("√"); Thread.sleep(sleepTime); number5.setText(n[i] + ""); break; case 6: right6.setText("√"); Thread.sleep(sleepTime); number6.setText(n[i] + ""); break; case 7: setNull(); right7.setText("√"); Thread.sleep(sleepTime); number7.setText(n[i] + ""); break; case 8: right8.setText("√"); Thread.sleep(sleepTime); number8.setText(n[i] + ""); break; } Thread.sleep(sleepTime); } //否则的话:淘汰未来不会再使用或者最久被使用的页面 else { int max = -1; //依次遍历内存中页面 for (int k = 0; k < temp.length; k++) { int tem = 0; //从当前的要装入内存的页面开始遍历数组,找出最久被使用的页面淘汰 for (int j = i; j < n.length; j++) { if (temp[k] == n[j]) { if (j > max) { max = j; } //如果将要进入内存的页面中有在内存中的页面temp[k]时,另tem = 1 tem = 1; break; } } //如果temp[k]在将要装入内存的页面中不存在则将其淘汰,将n[i]换入 if (tem == 0) { int temp_1 = temp[k]; temp[k] = n[i]; messageTextArea.append(new SimpleDateFormat( "yyyy-MM-dd hh:mm:ss").format(new Date()) + ": " + n[i] + "号页被装入内存," + temp_1 + "号页被换出,物理块的结果为: " + outPut(temp)); messageTextArea.append("\n"); setNull(); switch (k + 1) { case 1: error1.setText("×"); Thread.sleep(sleepTime); right1.setText("√"); Thread.sleep(sleepTime); number1.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 2: error2.setText("×"); Thread.sleep(sleepTime); right2.setText("√"); Thread.sleep(sleepTime); number2.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 3: error3.setText("×"); Thread.sleep(sleepTime); right3.setText("√"); Thread.sleep(sleepTime); number3.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 4: error4.setText("×"); Thread.sleep(sleepTime); right4.setText("√"); Thread.sleep(sleepTime); number4.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 5: error5.setText("×"); Thread.sleep(sleepTime); right5.setText("√"); Thread.sleep(sleepTime); number5.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 6: error6.setText("×"); Thread.sleep(sleepTime); right6.setText("√"); Thread.sleep(sleepTime); number6.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 7: error7.setText("×"); Thread.sleep(sleepTime); right7.setText("√"); Thread.sleep(sleepTime); number7.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 8: error8.setText("×"); Thread.sleep(sleepTime); right8.setText("√"); Thread.sleep(sleepTime); number8.setText(n[i] + ""); Thread.sleep(sleepTime); break; } b = false; line++; break; } } //如果在内存中页面在将要装入内存的页面中都将被使用,则将最久被使用的页面淘汰 if (b) { for (int j = 0; j < temp.length; j++) { if (temp[j] == n[max]) { int temp_1 = temp[j]; temp[j] = n[i]; messageTextArea.append(new SimpleDateFormat( "yyyy-MM-dd hh:mm:ss").format(new Date()) + ": " + n[i] + "号页被装入内存," + temp_1 + "号页被换出,物理块的结果为: " + outPut(temp)); messageTextArea.append("\n"); setNull(); switch (j + 1) { case 1: error1.setText("×"); Thread.sleep(sleepTime); right1.setText("√"); Thread.sleep(sleepTime); number1.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 2: error2.setText("×"); Thread.sleep(sleepTime); right2.setText("√"); Thread.sleep(sleepTime); number2.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 3: error3.setText("×"); Thread.sleep(sleepTime); right3.setText("√"); Thread.sleep(sleepTime); number3.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 4: error4.setText("×"); Thread.sleep(sleepTime); right4.setText("√"); Thread.sleep(sleepTime); number4.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 5: error5.setText("×"); Thread.sleep(sleepTime); right5.setText("√"); Thread.sleep(sleepTime); number5.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 6: error6.setText("×"); Thread.sleep(sleepTime); right6.setText("√"); Thread.sleep(sleepTime); number6.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 7: error7.setText("×"); Thread.sleep(sleepTime); right7.setText("√"); Thread.sleep(sleepTime); number7.setText(n[i] + ""); Thread.sleep(sleepTime); break; case 8: error8.setText("×"); Thread.sleep(sleepTime); right8.setText("√"); Thread.sleep(sleepTime); number8.setText(n[i] + ""); Thread.sleep(sleepTime); break; } line++; break; } } } } } //如果要装入内存中的页面,内存中已存在 else { messageTextArea.append(new SimpleDateFormat( "yyyy-MM-dd hh:mm:ss").format(new Date()) + ": " + n[i] + "号页已在内存,物理块的结果为: " + outPut(temp)); messageTextArea.append("\n"); Thread.sleep(sleepTime); } } double number = line; double sum = n.length; //计算出页面中断的次数、页面个数和缺页中断率。 messageTextArea.append("缺页中断次数:" + line + ", 页面序列的总长度:" + n.length + ", 缺页中断率:" + number / sum * 100 + "%"); } public void NRU(int n[], int num, int sleepTime) throws InterruptedException { //存放内存中的页面 int temp[] = new int[num]; //存放内存中页面的访问位 int bit[] = new int[num]; //初始化内存中的页面与访问位 for (int i = 0; i < temp.length; i++) { temp[i] = -1; bit[i] = -1; } //内存数组的下标 int line = 0; //访问位数组的下标 int line_k = 0; for (int i = 0; i < n.length; i++) { //标记位 boolean b = true; //如果内存中存在将要进入的页面将其下标记录 int temp_index = -1; //判断一下内存中是否有将要装入内存的页面 for (int j = 0; j < temp.length; j++) { if (n[i] == temp[j]) { b = false; temp_index = j; break; } } //如果没有 if (b) { //当物理块没有装满时,依次将要装入的页面装入内存 if (line < num) { //依次装入内存数组 temp[line++] = n[i]; //依次装入页面的访问位置为1 bit[line_k++] = 1; //打印信息 messageTextArea.append(new SimpleDateFormat( "yyyy-MM-dd hh:mm:ss").format(new Date()) + ": " + n[i] + "号页被装入内存,物理块的结果为: " + outPut(temp)); messageTextArea.append("\n"); Thread.sleep(sleepTime); //将页面后的组件清空 setNull(); //将进入内存的页面初始化 switch (line) { case 1: right1.setText("A=1"); error1.setText("√"); Thread.sleep(sleepTime); number1.setText(n[i] + ""); break; case 2: right2.setText("A=1"); error2.setText("√"); Thread.sleep(sleepTime); number2.setText(n[i] + ""); break; case 3: right3.setText("A=1"); error3.setText("√"); Thread.sleep(sleepTime); number3.setText(n[i] + ""); break; case 4: right4.setText("A=1"); error4.setText("√"); Thread.sleep(sleepTime); number4.setText(n[i] + ""); break; case 5: right5.setText("A=1"); error5.setText("√"); Thread.sleep(sleepTime); number5.setText(n[i] + ""); break; case 6: right6.setText("A=1");
最近下载更多
谢谢ddss LV1
2023年6月7日
m0NESY LV1
2023年2月21日
yiciyinghua LV1
2022年11月29日
zhendong LV7
2022年3月6日
1932332106 LV1
2021年12月22日
1932332229 LV1
2021年12月21日
Rossi_L LV1
2021年11月25日
msaisai LV1
2021年6月6日
158186 LV1
2021年5月29日
我是你爸爸啊啊啊 LV1
2020年12月15日
最近浏览更多
sswert LV2
9月12日
郭珈希
2023年12月25日
暂无贡献等级
孟凡玉
2023年11月15日
暂无贡献等级
谢谢ddss LV1
2023年6月7日
nnn0x0922_
2023年6月6日
暂无贡献等级
m0NESY LV1
2023年2月21日
yiciyinghua LV1
2022年11月29日
xuexizhuanyong23 LV16
2022年10月18日
8326586
2022年6月5日
暂无贡献等级
小阿九
2022年6月1日
暂无贡献等级