Java实现FIFO、LRU、LFU、OPT四页面置换算法

news2024/11/27 12:04:54

题目要求

采用多道程序思想设计一个程序,模拟页存储管理地址变换的过程,可采用FIFO、LRU、LFU、OPT四页面置换算法。基本要求如下:

  1. 需要建立访问页表线程、访问快表线程、缺页中断处理线程、访问内存线程等,协同这些线程模拟完成地址变换的过程。
  2. 输入一个逻辑页面访问序列和随机产生逻辑页面访问序列,分别由四个算法完成页面置换;
  3. 能够设定驻留内存页面的个数、内存的存取时间、缺页中断的时间、快表的时间,并提供合理省缺值,可以暂停和继续系统的执行;
  4. 能够设定页号序列中逻辑页面个数和范围;
  5. 能够设定有快表和没有快表的运行模式;
  6. 提供良好图形界面,同时能够展示四个算法运行的结果;
  7. 给出每种页面置换算法每个页面的存取时间;
  8. 能够将每次的实验输入和实验结果存储起来,随时可查询;
  9. 完成多次不同设置的实验,总结实验数据,看看能得出什么结论。

github地址

运行界面

执行界面

image-20221229161057165

保存界面

image-20221229161155749

历史界面

image-20221229161213272

具体代码

四种页面置换算法具体实现

config

package com.lr.algurithm;

public class config {

   public static int page_low = 0;
   public static int page_high = 0;
   public static int page_list_low = 0;
   public static int page_list_high = 0;

   public static int run_time = 0;

   public static int quick_table_num = 0;//快表大小
   public static int memory_num = 0;//内存块数
   public static double memory_access = 0;//内存存取时间
   public static double quick_table_access = 0;//快表存取时间
   public static double miss_page_interrupt = 0;//缺页中断处理时间
   public static int taskSize = 0;//页面序列数量
   public static int[] task = new int[taskSize];//页面序列存放
   public static boolean is_check=false;//快表启用判断

}

FIFO算法

FIFO

package com.lr.algurithm;

import com.lr.frame.Page;
import sun.awt.Mutex;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;

public class FIFO extends Thread{

   private int fifo_i = 0;
   public int fifo_lackpage=0;//缺页数
   public double fifo_ave_time=0;//平均时间
   public double fifo_total_time=0;//总时间
   public List<Integer> fifo_memory_page = new ArrayList<>();//内存现有页数存放
   public List<Integer> fifo_quick_table_page = new ArrayList<>();//快表现有页数存放
   public Mutex pause = new Mutex();
   public String snumber = new String();
   public String interruption = new String();
   public String totalTime = new String();
   public String avrTime = new String();
   public String missPage = new String();

   public double start(int a, double per_time) {
      if (!config.is_check) { //无快表模式
         if (!fifo_memory_page.contains(a)) { //不在内存,产生缺页中断
            fifo_lackpage ++ ;
            if (fifo_memory_page.size() < config.memory_num)
               fifo_memory_page.add(a);
            else {
               fifo_memory_page.remove(0);
               fifo_memory_page.add(a);
            }
            fifo_total_time += 3 * config.memory_access + config.miss_page_interrupt;
            per_time += 3 * config.memory_access + config.miss_page_interrupt;
         } else {
            fifo_total_time += 2 * config.memory_access;
            per_time += 2 * config.memory_access;
         }
      }
      else { //快表模式
         if (!fifo_quick_table_page.contains(a)) { //不在快表
            if (!fifo_memory_page.contains(a)) { //不在内存,产生缺页中断
               fifo_lackpage ++ ;
               if (fifo_memory_page.size() < config.memory_num) //内存块未满,直接调入
                  fifo_memory_page.add(a);
               else {
                  fifo_memory_page.remove(0);
                  fifo_memory_page.add(a);
               }

               //快表置换用FIFO
               if (fifo_quick_table_page.size() < config.quick_table_num)
                  fifo_quick_table_page.add(a);
               else {
                  fifo_quick_table_page.remove(0);
                  fifo_quick_table_page.add(a);
               }
               fifo_total_time += 3 * config.memory_access + config.miss_page_interrupt;
               per_time += 3 * config.memory_access + config.miss_page_interrupt;
            } else { //在内存
               fifo_total_time += 2 * config.memory_access;
               per_time += 2 * config.memory_access;
            }
         }  else { //在快表
            fifo_total_time += config.quick_table_access + config.memory_access;
            per_time += config.quick_table_access + config.memory_access;;
         }
      }
      return per_time;
   }

   @Override
   public void run() {
      super.run();
      for(fifo_i = 0; fifo_i < config.taskSize; fifo_i ++ ) {
         pause.lock();

         double per_time = 0;
         per_time = start(config.task[fifo_i], per_time);
         String str1="查找";
         String s1 = String.valueOf(config.task[fifo_i]);
         snumber += str1;
         snumber += s1;
         snumber += ":";

         for (int j = 0; j < config.memory_num; j ++ ) {
            if (j < fifo_memory_page.size()) {
               String s = String.valueOf(fifo_memory_page.get(j));
               snumber += s;
               snumber += " ";
            }
            else {
               snumber += " ";
            }
         }
         pause.unlock();
         BigDecimal bd = new BigDecimal(per_time);
         bd = bd.setScale(2, RoundingMode.HALF_UP);
         snumber += "耗费时间:" + bd + "\n";
         Page.FIFOtest.append(snumber);
         snumber = "";
         try {
            sleep(config.run_time);//睡眠300ms
         } catch (InterruptedException e) {
            e.printStackTrace();
         }
      }
      String s1 = String.valueOf(config.taskSize);
      s1 = String.valueOf(fifo_lackpage);
      interruption = s1 + "次";

      // emit fifo_updata(s1+"次","interrupt_label");
      double d = (double)fifo_lackpage / config.taskSize * 100;
      BigDecimal bd = new BigDecimal(d);
      bd = bd.setScale(2, RoundingMode.HALF_UP);
      totalTime = String.valueOf(fifo_total_time);
      fifo_ave_time = fifo_total_time / config.taskSize;
      BigDecimal bda = new BigDecimal(fifo_ave_time);
      bda = bda.setScale(2, RoundingMode.HALF_UP);
      avrTime = String.valueOf(bda);
      missPage = bd + "%";
      Page.fifo_interrupt_label.setText(interruption);
      Page.fifo_total_time_label.setText(totalTime);
      Page.fifo_ave_time_label.setText(avrTime);
      Page.fifo_miss_page_label.setText(missPage);
      // System.out.println("fifo:"+s1);
      // System.out.println("fifo:"+fifo_total_time);
      // System.out.println("fifo:"+fifo_ave_time);
      // System.out.println("fifo:"+d + "%");

   }
}

LRU算法

LRU

package com.lr.algurithm;

import com.lr.frame.Page;
import sun.awt.Mutex;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;

public class LRU extends Thread {

   private int lru_i = 0;
   public int lru_lackpage=0;//缺页数
   public double lru_ave_time=0;//平均时间
   public double lru_total_time=0;//总时间
   public List<Integer> lru_memory_page = new ArrayList<>();//内存现有页数存放
   public List<Integer> lru_quick_table_page = new ArrayList<>();//快表现有页数存放
   public Mutex pause = new Mutex();
   public String snumber = new String();
   public String interruption = new String();
   public String totalTime = new String();
   public String avrTime = new String();
   public String missPage = new String();

   public double start(int a, double per_time) {
      if(!config.is_check) { //无快表模式

         if(!lru_memory_page.contains(a)) { //不在内存,产生缺页中断
            lru_lackpage ++ ;
            if(lru_memory_page.size() < config.memory_num) {
               lru_memory_page.add(a);
            } else {
               lru_memory_page.remove(0);
               lru_memory_page.add(a);
            }
            lru_total_time += 3 * config.memory_access + config.miss_page_interrupt;
            per_time += 3 * config.memory_access + config.miss_page_interrupt;
         }
         else { //在内存中则找出这个元素并删除,在末尾添加这个元素,保证最近访问的置于末尾
            // if (a < lru_memory_page.size())
            int temp = 0;
            for (int i = 0; i < lru_memory_page.size(); ++ i) {
               if (a == lru_memory_page.get(i))
                  temp = i;
            }
            lru_memory_page.remove(temp);
            // System.out.println(a);
            lru_memory_page.add(a);
            lru_total_time += 2 * config.memory_access;
            per_time += 2 * config.memory_access;
         }
      }
      else { //快表模式
         if(!lru_quick_table_page.contains(a)) { //不在快表
            if(!lru_memory_page.contains(a)) { //不在内存,产生缺页中断
               lru_lackpage ++ ;
               if(lru_memory_page.size() < config.memory_num) { //内存块未满,直接调入
                  lru_memory_page.add(a);
               } else {
                  lru_memory_page.remove(0);
                  lru_memory_page.add(a);
               }
               //快表置换用FIFO
               if(lru_quick_table_page.size() < config.quick_table_num) {
                  lru_quick_table_page.add(a);
               } else {
                  lru_quick_table_page.remove(0);
                  lru_quick_table_page.add(a);
               }
               lru_total_time += 3 * config.memory_access + config.miss_page_interrupt;
               per_time += 3 * config.memory_access + config.miss_page_interrupt;
            }
            else { //在内存
               int temp = 0;
               for (int i = 0; i < lru_memory_page.size(); ++ i) {
                  if (a == lru_memory_page.get(i))
                     temp = i;
               }
               lru_memory_page.remove(temp);
               lru_memory_page.add(a);
               lru_total_time += 2 * config.memory_access;
               per_time += 2 * config.memory_access;
            }
         } else { //在快表
            int temp = 0;
            for (int i = 0; i < lru_memory_page.size(); ++ i) {
               if (a == lru_memory_page.get(i))
                  temp = i;
            }
            lru_memory_page.remove(temp);
            lru_memory_page.add(a);
            lru_total_time += config.quick_table_access + config.memory_access;
            per_time += config.quick_table_access + config.memory_access;
         }
      }
      return per_time;
   }

   @Override
   public void run() {
      for (lru_i = 0; lru_i < config.taskSize; lru_i ++ ) {
         pause.lock();

         double per_time = 0;
         per_time = start(config.task[lru_i],per_time);
         String str1="查找";
         String s1 = String.valueOf(config.task[lru_i]);
         snumber += str1;
         snumber += s1;
         snumber += ":";

         for (int j = 0; j < config.memory_num; j ++ ) {
            if (j < lru_memory_page.size()) {
               String s = String.valueOf(lru_memory_page.get(j));
               snumber+=s;
               snumber+=" ";
            } else {
               snumber+=" ";
            }
         }
         pause.unlock();
         BigDecimal bd = new BigDecimal(per_time);
         bd = bd.setScale(2, RoundingMode.HALF_UP);
         snumber += "耗费时间:" + bd.toString() + "\n";
         Page.LRUtest.append(snumber);
         snumber = "";
         try {
            sleep(config.run_time);
         } catch (InterruptedException e) {
            e.printStackTrace();
         }
      }
      String s1 = String.valueOf(config.taskSize);
      s1 = String.valueOf(lru_lackpage);
      interruption = s1 + "次";
      double d = (double)lru_lackpage / config.taskSize * 100;
      BigDecimal bd = new BigDecimal(d);
      bd = bd.setScale(2, RoundingMode.HALF_UP);
      lru_ave_time = (double)lru_total_time / config.taskSize;
      totalTime = String.valueOf(lru_total_time);
      BigDecimal bda = new BigDecimal(lru_ave_time);
      bda = bda.setScale(2, RoundingMode.HALF_UP);
      avrTime = String.valueOf(bda);
      missPage = bd + "%";
      Page.lru_interrupt_label.setText(interruption);
      Page.lru_total_time_label.setText(totalTime);
      Page.lru_ave_time_label.setText(avrTime);
      Page.lru_miss_page_label.setText(missPage);
      // System.out.println("lru"+s1);
      // System.out.println("lru"+lru_total_time);
      // System.out.println("lru"+lru_ave_time);
      // System.out.println("lru"+d + "%");
   }
}

LFU算法

LFU

package com.lr.algurithm;

import com.lr.frame.Page;
import com.lr.tool.Node;
import sun.awt.Mutex;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;

public class LFU extends Thread {

   private int lfu_i = 0;
   public int lfu_lackpage=0;//缺页数
   public double lfu_ave_time=0;//平均时间
   public double lfu_total_time=0;//总时间
   public List<Node> lfu_memory_page = new ArrayList<>();//内存现有页数存放
   public List<Integer> lfu_quick_table_page = new ArrayList<>();//快表现有页数存放
   public Mutex pause = new Mutex();
   public String snumber = new String();
   public String interruption = new String();
   public String totalTime = new String();
   public String avrTime = new String();
   public String missPage = new String();

   public double start(int a, double per_time) {
      if(!config.is_check) { //无快表模式
         boolean flag = true;
         int index = 0;
         for (Node map:lfu_memory_page) {
            if(map.key == a) {
               flag = false;
               break;
            }
            index ++ ;
         }

         if (flag) { //不在内存
            lfu_lackpage ++ ;
            //内存满,删去访问频率最小的那个,相等的频率按fifo删除
            if(lfu_memory_page.size() >= config.memory_num) {
               Node min_obj;
               min_obj = lfu_memory_page.get(0);
               for (Node pair : lfu_memory_page) {
                  if (pair.value < min_obj.value) {
                     min_obj = pair;
                  }
               }
               lfu_memory_page.remove(min_obj);
            }
            lfu_memory_page.add(new Node(a));
            lfu_total_time += 3 * config.memory_access + config.miss_page_interrupt;
            per_time += 3 * config.memory_access + config.miss_page_interrupt;
         } else {

            lfu_memory_page.get(index).value++;
            lfu_total_time += 2 * config.memory_access;
            per_time += 2 * config.memory_access;
         }
      } else { //快表模式
         if(!lfu_quick_table_page.contains(a))//不在快表
         {
            boolean flag = true;
            int index = 0;
            for (Node map : lfu_memory_page) {
               if (map.key == a) {
                  flag = false;
                  break;
               }
               index ++ ;
            }

            if (flag) { //不在内存
               lfu_lackpage ++ ;
               //内存满,删去访问频率最小的那个,相等的频率按lfu删除
               if (lfu_memory_page.size() >= config.memory_num) {
                  Node min_obj;
                  min_obj = lfu_memory_page.get(0);
                  for (Node map : lfu_memory_page) {
                     if(map.value < min_obj.value) {
                        min_obj = map;
                     }
                  }
                  lfu_memory_page.remove(min_obj);
               }

               lfu_memory_page.add(new Node(a));

               //快表置换用FIFO
               if (lfu_quick_table_page.size() < config.quick_table_num) {
                  lfu_quick_table_page.add(a);
               } else {
                  lfu_quick_table_page.remove(0);
                  lfu_quick_table_page.add(a);
               }

               lfu_total_time += 3 * config.memory_access + config.miss_page_interrupt;
               per_time += 3 * config.memory_access + config.miss_page_interrupt;
            } else { //在内存
               lfu_memory_page.get(index).value++;

               lfu_total_time += 2 * config.memory_access;
               per_time += 2 * config.memory_access;
            }
         } else { //在快表
            int index = 0;
            for (Node map : lfu_memory_page) {
               if(map.key == a) {
                  lfu_memory_page.get(index).value++;
                  break;
               }
               index++;
            }
            lfu_total_time += config.quick_table_access + config.memory_access;
            per_time += config.quick_table_access + config.memory_access;
         }
      }
      return per_time;
   }

   @Override
   public void run() {
      for(lfu_i = 0; lfu_i < config.taskSize; lfu_i ++ ) {
         pause.lock();
         double per_time = 0;
         per_time = start(config.task[lfu_i], per_time);
         String str1 = "查找";
         String s1 = String.valueOf(config.task[lfu_i]);
         snumber += str1;
         snumber += s1;
         snumber += ":";

         for (int j = 0; j < config.memory_num; j ++) {
            if (j < lfu_memory_page.size()) {
               String s = String.valueOf(lfu_memory_page.get(j).key);
               snumber+=s;
               snumber+=" ";
            } else {
               snumber+=" ";
            }
         }
         pause.unlock();
         BigDecimal bd = new BigDecimal(per_time);
         bd = bd.setScale(2, RoundingMode.HALF_UP);
         snumber += "耗费时间:" + bd + "\n";
         Page.LFUtest.append(snumber);
         snumber = "";
         try {
            sleep(config.run_time);
         } catch (InterruptedException e) {
            e.printStackTrace();
         }
      }
      String s1 = String.valueOf(config.taskSize);
      s1 = String.valueOf(lfu_lackpage);
      interruption = s1 + "次";
      double d = (double)lfu_lackpage / config.taskSize * 100;
      BigDecimal bd = new BigDecimal(d);
      bd = bd.setScale(2, RoundingMode.HALF_UP);
      lfu_ave_time = (double)lfu_total_time / config.taskSize;
      totalTime = String.valueOf(lfu_total_time);
      BigDecimal bda = new BigDecimal(lfu_ave_time);
      bda = bda.setScale(2, RoundingMode.HALF_UP);
      avrTime = String.valueOf(bda);
      missPage = bd + "%";
      Page.lfu_interrupt_label.setText(interruption);
      Page.lfu_total_time_label.setText(totalTime);
      Page.lfu_ave_time_label.setText(avrTime);
      Page.lfu_miss_page_label.setText(missPage);
      // System.out.println("lfu"+s1);
      // System.out.println("lfu"+lfu_total_time);
      // System.out.println("lfu"+lfu_ave_time);
      // System.out.println("lfu"+d + "%");
   }
}

Node

package com.lr.tool;

public class Node {
   public int key;
   public int value;
   public Node() {
      key = 0;
      value = 0;
   }
   public Node(int Key) {
      key = Key;
      value = 1;
   }

   public Node(int a, int i) {
   }
}

OPT算法

OPT

package com.lr.algurithm;

import com.lr.frame.Page;
import sun.awt.Mutex;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class OPT extends Thread {

   private int opt_i = 0;
   public int opt_lackpage=0;//缺页数
   public double opt_ave_time=0;//平均时间
   public double opt_total_time=0;//总时间
   public List<Integer> opt_memory_page = new ArrayList<>();//内存现有页数存放
   // public int[] opt_memory_page = new int[config.taskSize];
   public List<Integer> opt_quick_table_page = new ArrayList<>();//快表现有页数存放
   public Mutex pause = new Mutex();
   public String snumber = new String();
   public String interruption = new String();
   public String totalTime = new String();
   public String avrTime = new String();
   public String missPage = new String();

   public double start(int a, double per_time) {
      if (!config.is_check) { //无快表模式
         if (!opt_memory_page.contains(a)) { //不在内存,产生缺页中断
            opt_lackpage ++ ;
            if (opt_memory_page.size() < config.memory_num) {
               opt_memory_page.add(a);
            } else { //遍历之后所有页号,与内存内页号相同则移到尾部,最后删除头部
               Map<Integer, Boolean> has_move = new HashMap<>();//移动过的不能再移动
               int cnt = 0;//移动次数要小于内存块数
               for (int j = 0; j < config.taskSize; j ++ ) {
                  has_move.put(config.task[j], false);
               }

               for (int j = opt_i + 1; j < config.taskSize; j ++ ) { //从需要进入内存的页号的后一位开始
                  if(opt_memory_page.contains(config.task[j])
                        && has_move.get(config.task[j]) != true
                        && cnt < config.memory_num - 1)
                  {
                     int temp = 0;
                     for (int i = 0; i < opt_memory_page.size(); ++ i) {
                        if (config.task[j] == opt_memory_page.get(i))
                           temp = i;
                     }
                     opt_memory_page.remove(temp);
                     opt_memory_page.add(config.task[j]);
                     has_move.put(config.task[j], true);
                     cnt ++ ;
                  }
               }
               opt_memory_page.remove(0);
               opt_memory_page.add(a);

            }
            opt_total_time += 3 * config.memory_access + config.miss_page_interrupt;
            per_time += 3 * config.memory_access + config.miss_page_interrupt;
         } else {
            opt_total_time += 2 * config.memory_access;
            per_time += 2 * config.memory_access;
         }
      } else { //快表模式
         if(!opt_quick_table_page.contains(a)) { //不在快表
            if(!opt_memory_page.contains(a)) { //不在内存,产生缺页中断
               opt_lackpage ++ ;
               if(opt_memory_page.size() < config.memory_num) { //内存块未满,直接调入
                  opt_memory_page.add(a);
               } else {
                  Map<Integer, Boolean> has_move = new HashMap<>();//移动过的不能再移动
                  int cnt = 0;//移动次数要小于内存块数
                  for (int j = 0; j < config.taskSize; j ++ ) {
                     has_move.put(config.task[j], false);
                  }
                  for(int j = opt_i + 1; j < config.taskSize; j ++ ) { //从需要进入内存的页号的后一位开始
                     if(opt_memory_page.contains(config.task[j])
                           && has_move.get(config.task[j]) != true
                           && cnt < config.memory_num - 1) {
                        int temp = 0;
                        for (int i = 0; i < opt_memory_page.size(); ++ i) {
                           if (config.task[j] == opt_memory_page.get(i))
                              temp = i;
                        }
                        opt_memory_page.remove(temp);
                        opt_memory_page.add(config.task[j]);
                        has_move.put(config.task[j], true);
                        cnt++;
                     }
                  }
                  opt_memory_page.remove(0);
                  opt_memory_page.add(a);
               }

               //快表置换用FIFO
               if(opt_quick_table_page.size() < config.quick_table_num) {
                  opt_quick_table_page.add(a);
               } else {
                  opt_quick_table_page.remove(0);
                  opt_quick_table_page.add(a);
               }
               opt_total_time += 3 * config.memory_access + config.miss_page_interrupt;
               per_time += 3 * config.memory_access + config.miss_page_interrupt;
            } else { //在内存

               opt_total_time += 2 * config.memory_access;
               per_time += 2 * config.memory_access;
            }
         } else { //在快表
            opt_total_time += config.quick_table_access + config.memory_access;
            per_time += config.quick_table_access + config.memory_access;
         }
      }
      return per_time;
   }

   @Override
   public void run() {
      for (opt_i = 0; opt_i < config.taskSize; opt_i ++ ) {
         pause.lock();

         double per_time = 0;
         per_time = start(config.task[opt_i], per_time);
         String str1="查找";
         String s1 = String.valueOf(config.task[opt_i]);
         snumber += str1;
         snumber += s1;
         snumber += ":";

         for (int j = 0; j < config.memory_num; j ++ ) {
            if (j < opt_memory_page.size()) {
               String s = String.valueOf(opt_memory_page.get(j));
               snumber += s;
               snumber += " ";
            } else {
               snumber+=" ";
            }
         }
         pause.unlock();
         BigDecimal bd = new BigDecimal(per_time);
         bd = bd.setScale(2, RoundingMode.HALF_UP);
         snumber += "耗费时间:" + bd + "\n";
         Page.OPTtest.append(snumber);
         snumber = "";
         try {
            sleep(config.run_time);
         } catch (InterruptedException e) {
            e.printStackTrace();
         }
      }
      String s1 = String.valueOf(config.taskSize);
      s1 = String.valueOf(opt_lackpage);
      interruption = s1 + "次";
      double d = (double)opt_lackpage / config.taskSize * 100;
      BigDecimal bd = new BigDecimal(d);
      bd = bd.setScale(2, RoundingMode.HALF_UP);
      opt_ave_time = (double)opt_total_time / config.taskSize;
      totalTime = String.valueOf(opt_total_time);
      BigDecimal bda = new BigDecimal(opt_ave_time);
      bda = bda.setScale(2, RoundingMode.HALF_UP);
      avrTime = String.valueOf(bda);
      missPage = bd + "%";
      Page.opt_interrupt_label.setText(interruption);
      Page.opt_total_time_label.setText(totalTime);
      Page.opt_ave_time_label.setText(avrTime);
      Page.opt_miss_page_label.setText(missPage);
      // System.out.println("opt"+s1);
      // System.out.println("opt"+opt_total_time);
      // System.out.println("opt"+opt_ave_time);
      // System.out.println("opt"+d + "%");
   }
}

连接数据库

保存记录

Save

package com.lr.db;

import java.sql.*;

import com.lr.frame.Page;
import com.lr.algurithm.config;

import javax.swing.*;

public class Save {

   private static String url = null;
   private static String username = null;
   private static String password = null;

   private static Connection conn = null;
   private static Statement st = null;

   public Save() {
      try {
         saveRecord();
      } catch (SQLException throwables) {
         throwables.printStackTrace();
      } catch (ClassNotFoundException e) {
         e.printStackTrace();
      } finally {
         if (st != null) {
            try {
               st.close();
            } catch (SQLException throwables) {
               throwables.printStackTrace();
            }
         }
         if (conn != null) {
            try {
               conn.close();
            } catch (SQLException throwables) {
               throwables.printStackTrace();
            }
         }
      }
   }


   public void saveRecord() throws SQLException, ClassNotFoundException {
      //1.加载驱动
      //DriverManager.registerDriver(new com.mysql.jdbc.Driver());
      Class.forName("com.mysql.jdbc.Driver");//固定写法

      //2.用户信息和
      url = "jdbc:mysql://127.0.0.1:3306/os?useUnicode=true&characterEncoding=utf8&useSSL=true";
      username = "root";
      password = "123456";

      //3.连接成功,数据库对象  Connection  代表数据库
      conn = DriverManager.getConnection(url, username, password);
      //4.获得SQL的执行对象
      st = conn.createStatement();

      String sql = "INSERT INTO test(memory_n,page_n,page_list,memory_t,quick_table_t," +
            "interrupt_t,is_check,fifo_total_t,fifo_ave_t,fifo_miss_page,fifo_interrupt_n," +
            "fifo_text,lru_total_t,lru_ave_t,lru_miss_page,lru_interrupt_n,lru_text," +
            "lfu_total_t,lfu_ave_t,lfu_miss_page,lfu_interrupt_n,lfu_text,opt_total_t," +
            "opt_ave_t,opt_miss_page,opt_interrupt_n,opt_text)VALUES('" + config.memory_num + "','" +
            config.taskSize + "','" + Page.task_edit.getText() + "','" + config.memory_access + "','" +
            config.quick_table_access + "','" + config.miss_page_interrupt + "','" +
            config.is_check + "','" + Page.fifo_total_time_label.getText() +  "','" +
            Page.fifo_ave_time_label.getText() +  "','" + Page.fifo_miss_page_label.getText() +  "','" +
            Page.fifo_interrupt_label.getText() +  "','" + Page.FIFOtest.getText() + "','" +
            Page.lru_total_time_label.getText() +  "','" + Page.lru_ave_time_label.getText() +  "','" +
            Page.lru_miss_page_label.getText() +  "','" + Page.lru_interrupt_label.getText() +  "','" +
            Page.LRUtest.getText() + "','" + Page.lfu_total_time_label.getText() +  "','" +
            Page.lfu_ave_time_label.getText() +  "','" + Page.lfu_miss_page_label.getText() +  "','" +
            Page.lfu_interrupt_label.getText() +  "','" + Page.LFUtest.getText() + "','" +
            Page.opt_total_time_label.getText() +  "','" + Page.opt_ave_time_label.getText() +  "','" +
            Page.opt_miss_page_label.getText() +  "','" + Page.opt_interrupt_label.getText() +  "','" +
            Page.OPTtest.getText() + "')";
      int i = st.executeUpdate(sql);
      if (i > 0) {
         JOptionPane.showMessageDialog(null, "保存成功", "提交信息", 1);
      } else {
         JOptionPane.showMessageDialog(null, "保存失败", "warning", JOptionPane.ERROR_MESSAGE);
      }

   }

   public static void main(String[] args) {
      new Save();
   }
}

历史记录

History

package com.lr.db;

import javax.swing.*;
import java.awt.*;
import java.sql.*;

public class History {
   private static String url=null;
   private static String username=null;
   private static String password=null;
   private JFrame frame;

   public History() {
      frame = new JFrame("历史记录");
      // frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); // 退出应用程序默认窗口关闭
      // //获取与系统相关的默认工具类对象
      Toolkit toolkit = Toolkit.getDefaultToolkit();
      //获取屏幕分辨率
      Dimension d = toolkit.getScreenSize();
      frame.setBounds((int)(d.getWidth() - 1000) / 2,(int)(d.getHeight() - 850) / 2,
            1000, 850);
      frame.setVisible(true);

      try {
         historyRecord();
      } catch (ClassNotFoundException cnfe) {
         cnfe.printStackTrace();
         JOptionPane.showMessageDialog(null, "数据源错误", "错误", JOptionPane.ERROR_MESSAGE);
      } catch (SQLException sqle) {
         sqle.printStackTrace();
         JOptionPane.showMessageDialog(null, "数据操作错误", "错误", JOptionPane.ERROR_MESSAGE);
      }


   }

   public void historyRecord() throws SQLException, ClassNotFoundException {
      //1.加载驱动
      //DriverManager.registerDriver(new com.mysql.jdbc.Driver());
      Class.forName("com.mysql.jdbc.Driver");//固定写法

      //2.用户信息和
      url="jdbc:mysql://127.0.0.1:3306/os?useUnicode=true&characterEncoding=utf8&useSSL=true";
      username="root";
      password="123456";

      //3.连接成功,数据库对象  Connection  代表数据库
      Connection conn=DriverManager.getConnection(url,username,password);

      //4.执行SQL的对象,去执行SQL,可能存在结果,返回结果信息
      String sql = "select * from test";
      PreparedStatement pstm = conn.prepareStatement(sql);
      ResultSet rs = pstm.executeQuery();
      // ResultSet rs=statement.executeQuery(sql);
      int count = 0;
      while (rs.next()) {
         count++;
      }
      rs = pstm.executeQuery();

      // 将查询获得的记录数据,转换成适合生成JTable的数据形式
      Object[][] info = new Object[count][27];

      Object[] title = {"内存块数", "页面大小", " 页号序列", "内存存取时间", "快表存取时间",
            "中断执行时间", "是否勾选快表", "FIFO总时间", "FIFO平均时间", "FIFO缺页率",
            "FIFO中断次数", "FIFO执行过程", "LRU总时间", "LRU平均时间", "LRU缺页率",
            "LRU中断次数", "LRU执行过程", "LFU总时间", "LFU平均时间", "LFU缺页率",
            "LFU中断次数", "LFU执行过程", "OPT总时间", "OPT平均时间", "OPT缺页率",
            "OPT中断次数", "OPT执行过程"};

      count = 0;
      while (rs.next()) {
         // info[count][0] = rs.getObject("id");
         info[count][0] = rs.getObject("memory_n");
         info[count][1] = rs.getObject("page_n");
         info[count][2] = rs.getObject("page_list");
         info[count][3] = rs.getObject("memory_t");
         info[count][4] = rs.getObject("quick_table_t");
         info[count][5] = rs.getObject("interrupt_t");
         info[count][6] = rs.getObject("is_check");
         info[count][7] = rs.getObject("fifo_total_t");
         info[count][8] = rs.getObject("fifo_ave_t");
         info[count][9] = rs.getObject("fifo_miss_page");
         info[count][10] = rs.getObject("fifo_interrupt_n");
         info[count][11] = rs.getObject("fifo_text");
         info[count][12] = rs.getObject("lru_total_t");
         info[count][13] = rs.getObject("lru_ave_t");
         info[count][14] = rs.getObject("lru_miss_page");
         info[count][15] = rs.getObject("lru_interrupt_n");
         info[count][16] = rs.getObject("lru_text");
         info[count][17] = rs.getObject("lfu_total_t");
         info[count][18] = rs.getObject("lfu_ave_t");
         info[count][19] = rs.getObject("lfu_miss_page");
         info[count][20] = rs.getObject("lfu_interrupt_n");
         info[count][21] = rs.getObject("lfu_text");
         info[count][22] = rs.getObject("opt_total_t");
         info[count][23] = rs.getObject("opt_ave_t");
         info[count][24] = rs.getObject("opt_miss_page");
         info[count][25] = rs.getObject("opt_interrupt_n");
         info[count][26] = rs.getObject("opt_text");
         count++;
      }

      JTable table = new JTable(info, title);

      // 设置表格内容颜色
      table.setForeground(Color.BLACK);                   // 字体颜色
      table.setFont(new Font(null, Font.PLAIN, 14));      // 字体样式
      table.setSelectionForeground(Color.DARK_GRAY);      // 选中后字体颜色
      table.setSelectionBackground(Color.LIGHT_GRAY);     // 选中后字体背景
      table.setGridColor(Color.GRAY);                     // 网格颜色

      // 设置表头
      table.getTableHeader().setFont(new Font(null, Font.BOLD, 14));  // 设置表头名称字体样式
      table.getTableHeader().setForeground(Color.RED);                // 设置表头名称字体颜色
      table.getTableHeader().setReorderingAllowed(false);             // 设置不允许拖动重新排序各列

      // 设置行高
      table.setRowHeight(30);

      // 第一列列宽设置为40
      table.getColumnModel().getColumn(0).setPreferredWidth(40);

      table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
      JScrollPane scroll = new JScrollPane(table);

      frame.add(scroll);
      frame.setVisible(true);
      frame.pack();
   }

   public static void main(String[] args) {
      new History();
   }

}

GUI界面

Page

package com.lr.frame;

import com.lr.algurithm.FIFO;
import com.lr.algurithm.LFU;
import com.lr.algurithm.LRU;
import com.lr.algurithm.OPT;
import com.lr.algurithm.config;
import com.lr.db.History;
import com.lr.db.Save;

import javax.swing.*;
import java.awt.*;
import java.util.Arrays;
import java.util.List;

public class Page {
   public JFrame frame;
   private JPanel panel;
   public static TextArea FIFOtest;
   public static TextArea LRUtest;
   public static TextArea LFUtest;
   public static TextArea OPTtest;
   public static JTextField task_edit;
   public static JTextField memory_num_edit;
   public static JTextField taskSize_edit;
   public static JTextField taskSize_low_edit;
   public static JTextField taskSize_high_edit;
   public static JTextField task_low_edit;
   public static JTextField task_high_edit;
   public static JCheckBox quick_table_check;
   public static JTextField memory_access_edit;
   public static JTextField quick_table_access_edit;
   public static JTextField miss_page_interrupt_edit;
   public static JTextField run_time_edit;
   public static JLabel fifo_interrupt_label;
   public static JLabel fifo_miss_page_label;
   public static JLabel fifo_total_time_label;
   public static JLabel fifo_ave_time_label;
   public static JLabel lru_interrupt_label;
   public static JLabel lru_miss_page_label;
   public static JLabel lru_total_time_label;
   public static JLabel lru_ave_time_label;
   public static JLabel lfu_interrupt_label;
   public static JLabel lfu_miss_page_label;
   public static JLabel lfu_total_time_label;
   public static JLabel lfu_ave_time_label;
   public static JLabel opt_interrupt_label;
   public static JLabel opt_miss_page_label;
   public static JLabel opt_total_time_label;
   public static JLabel opt_ave_time_label;
   public static JTextField quick_table_num_edit;

   FIFO fifo = new FIFO();
   LRU lru = new LRU();
   LFU lfu = new LFU();
   OPT opt = new OPT();


   public Page() {
      frame = new JFrame();
      frame.setTitle("页面置换算法");
      //获取与系统相关的默认工具类对象
      Toolkit toolkit = Toolkit.getDefaultToolkit();
      //获取屏幕分辨率
      Dimension d = toolkit.getScreenSize();
      frame.setBounds((int)(d.getWidth() - 1185) / 2,(int)(d.getHeight() - 895) / 2,
            1185, 895);
      frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); // 退出应用程序默认窗口关闭
      frame.getContentPane().setLayout(null);
      // frame.setVisible(true);

      panel = new JPanel();
      panel.setBounds(10, 10, 1165, 890);
      frame.getContentPane().add(panel);
      panel.setLayout(null);


      JLabel label_1 = new JLabel("内存块数:");
      label_1.setBounds(35, 20, 100, 20);
      label_1.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(label_1);
      panel.add(label_1);

      memory_num_edit = new JTextField();
      memory_num_edit.setBounds(145, 20, 180, 20);
      // frame.getContentPane().add(memory_num_edit);
      panel.add(memory_num_edit);
      // memory_num_edit.setColumns(10);

      JLabel label_2 = new JLabel("页面数量:");
      label_2.setBounds(35, 60, 100, 20);
      label_2.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(label_2);
      panel.add(label_2);

      taskSize_edit = new JTextField();
      taskSize_edit.setBounds(145, 60, 180, 20);
      // frame.getContentPane().add(taskSize_edit);
      panel.add(taskSize_edit);

      taskSize_low_edit = new JTextField();
      taskSize_low_edit.setBounds(480, 60, 40, 20);
      // frame.getContentPane().add(taskSize_low_edit);
      panel.add(taskSize_low_edit);

      JLabel label_32 = new JLabel("-");
      label_32.setBounds(525, 60, 10, 20);
      label_32.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(label_32);
      panel.add(label_32);

      taskSize_high_edit = new JTextField();
      taskSize_high_edit.setBounds(540, 60, 40, 20);
      // frame.getContentPane().add(taskSize_high_edit);
      panel.add(taskSize_high_edit);

      JButton taskSize_btn = new JButton("随机生成");
      taskSize_btn.setBounds(350, 55, 120, 30);
      taskSize_btn.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(taskSize_btn);
      panel.add(taskSize_btn);
      taskSize_btn.addActionListener(e -> {
         if (!taskSize_low_edit.getText().isEmpty()) {
            config.page_low = Integer.parseInt(taskSize_low_edit.getText());
         } else {
            config.page_low = 1;
         }
         if (!taskSize_high_edit.getText().isEmpty())
            config.page_high = Integer.parseInt(taskSize_high_edit.getText());
         else
            config.page_high = 9;
         // int r = (int) Math.random();
         config.taskSize = (int) (config.page_low + Math.random() * (config.page_high - config.page_low + 1));
         taskSize_edit.setText(String.valueOf(config.taskSize));
      });

      JLabel label_3 = new JLabel("页面序号:");
      label_3.setBounds(35, 100, 100, 20);
      label_3.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(label_3);
      panel.add(label_3);

      task_low_edit = new JTextField();
      task_low_edit.setBounds(480, 100, 40, 20);
      // frame.getContentPane().add(task_low_edit);
      panel.add(task_low_edit);

      JLabel label_33 = new JLabel("-");
      label_33.setBounds(525, 100, 10, 20);
      label_33.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(label_33);
      panel.add(label_33);

      task_high_edit = new JTextField();
      task_high_edit.setBounds(540, 100, 40, 20);
      // frame.getContentPane().add(task_high_edit);
      panel.add(task_high_edit);

      task_edit = new JTextField();
      task_edit.setBounds(145, 100, 180, 20);
      // frame.getContentPane().add(task_edit);
      panel.add(task_edit);

      JButton task_btn = new JButton("随机生成");
      task_btn.setBounds(350, 95, 120, 30);
      task_btn.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(task_btn);
      panel.add(task_btn);
      task_btn.addActionListener(e -> {
         if (!task_low_edit.getText().isEmpty()) {
            config.page_list_low = Integer.parseInt(task_low_edit.getText());
         } else {
            config.page_list_low = 1;
         }
         if (!task_high_edit.getText().isEmpty())
            config.page_list_high = Integer.parseInt(task_high_edit.getText());
         else
            config.page_list_high = 9;
         config.taskSize = Integer.parseInt(taskSize_edit.getText());
         String list = "";
         config.task = new int[config.taskSize];
         int i = 0;
         for (; i < config.taskSize - 1; i ++ ) {
            config.task[i] = (int) (config.page_list_low + Math.random() * (config.page_list_high - config.page_list_low + 1));
            list += config.task[i] + ",";
         }
         config.task[i] = (int) (config.page_list_low + Math.random() * (config.page_list_high - config.page_list_low + 1));
         list += config.task[i];
         task_edit.setText(list);
      });

      JLabel label_15 = new JLabel("快表大小:");
      label_15.setBounds(35, 145, 100, 20);
      label_15.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(label_15);
      panel.add(label_15);

      quick_table_num_edit = new JTextField();
      quick_table_num_edit.setBounds(145, 145, 180, 20);
      // frame.getContentPane().add(quick_table_num_edit);
      panel.add(quick_table_num_edit);
      quick_table_num_edit.addActionListener(e -> {
         config.quick_table_num = Integer.parseInt(quick_table_num_edit.getText());
      });
      quick_table_num_edit.setEnabled(false);

      quick_table_check = new JCheckBox("启用快表");
      quick_table_check.setBounds(380, 145, 130, 30);
      quick_table_check.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(quick_table_check);
      panel.add(quick_table_check);
      quick_table_check.addActionListener(e -> {
         on_quick_table_check_clicked(quick_table_check.isSelected());
      });


      JLabel label_4 = new JLabel("内存存取时间:");
      label_4.setBounds(700, 20, 140, 20);
      label_4.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(label_4);
      panel.add(label_4);

      memory_access_edit = new JTextField();
      memory_access_edit.setBounds(845, 20, 50, 20);
      // frame.getContentPane().add(memory_access_edit);
      panel.add(memory_access_edit);

      JLabel label_34 = new JLabel("ms");
      label_34.setBounds(900, 20, 20, 20);
      label_34.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(label_34);
      panel.add(label_34);

      JLabel label_6 = new JLabel("快表存取时间:");
      label_6.setBounds(700, 60, 140, 20);
      label_6.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(label_6);
      panel.add(label_6);

      quick_table_access_edit = new JTextField();
      quick_table_access_edit.setBounds(845, 60, 50, 20);
      // frame.getContentPane().add(quick_table_access_edit);
      panel.add(quick_table_access_edit);

      JLabel label_35 = new JLabel("ms");
      label_35.setBounds(900, 60, 20, 20);
      label_35.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(label_35);
      panel.add(label_35);

      JLabel label_5 = new JLabel("缺页中断时间:");
      label_5.setBounds(700, 100, 140, 20);
      label_5.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(label_5);
      panel.add(label_5);

      miss_page_interrupt_edit = new JTextField();
      miss_page_interrupt_edit.setBounds(845, 100, 50, 20);
      // frame.getContentPane().add(miss_page_interrupt_edit);
      panel.add(miss_page_interrupt_edit);

      JLabel label_36 = new JLabel("ms");
      label_36.setBounds(900, 100, 20, 20);
      label_36.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(label_36);
      panel.add(label_36);

      JLabel label_16 = new JLabel("执行时间控制:");
      label_16.setBounds(700, 140, 140, 20);
      label_16.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(label_16);
      panel.add(label_16);

      run_time_edit = new JTextField();
      run_time_edit.setBounds(845, 140, 50, 20);
      // frame.getContentPane().add(run_time_edit);
      panel.add(run_time_edit);

      JLabel label_17 = new JLabel("ms");
      label_17.setBounds(900, 140, 20, 20);
      label_17.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(label_17);
      panel.add(label_17);

      JButton start_btn = new JButton("开始执行");
      start_btn.setBounds(200, 185, 120, 30);
      start_btn.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(start_btn);
      panel.add(start_btn);
      start_btn.addActionListener(e -> {
         on_clear_btn_clicked();
         config.memory_num = Integer.parseInt(memory_num_edit.getText());
         if (quick_table_check.isSelected()) {
            config.quick_table_num = Integer.parseInt(quick_table_num_edit.getText());
            if (quick_table_check.isSelected()  && config.quick_table_num >= config.memory_num) {
               JOptionPane.showMessageDialog(null, "快表大小应该小于内存大小", "warning", JOptionPane.ERROR_MESSAGE);
               return;
            }
         }

         config.memory_access = Double.parseDouble(memory_access_edit.getText());
         config.quick_table_access = Double.parseDouble(quick_table_access_edit.getText());
         config.miss_page_interrupt = Double.parseDouble(miss_page_interrupt_edit.getText());
         config.is_check = Boolean.parseBoolean(String.valueOf(quick_table_check.isSelected()));
         String str = task_edit.getText();
         List<String> lst = Arrays.asList(str.split(","));
         if (run_time_edit.getText().isEmpty()) {
            run_time_edit.setText("300");
         }
         config.run_time = Integer.parseInt(run_time_edit.getText());
         config.taskSize = lst.size();
         config.task = new int[config.taskSize];
         for (int i = 0; i < config.taskSize; ++ i) {
            str = lst.get(i);
            config.task[i] = Integer.parseInt(str);
         }
         new Thread(() -> fifo.run()).start();
         new Thread(() -> lru.run()).start();
         new Thread(() -> lfu.run()).start();
         new Thread(() -> opt.run()).start();

      });

      JButton stop_continue_btn = new JButton("暂停执行");
      stop_continue_btn.setBounds(500, 185, 120, 30);
      stop_continue_btn.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(stop_continue_btn);
      panel.add(stop_continue_btn);
      stop_continue_btn.addActionListener(e -> {
         if (stop_continue_btn.getText() == "暂停执行") {
            fifo.pause.lock();
            lru.pause.lock();
            lfu.pause.lock();
            opt.pause.lock();
            stop_continue_btn.setText("继续执行");
         } else {
            fifo.pause.unlock();
            lru.pause.unlock();
            lfu.pause.unlock();
            opt.pause.unlock();
            stop_continue_btn.setText("暂停执行");
         }
      });

      JButton stop_btn = new JButton("结束执行");
      stop_btn.setBounds(800, 185, 120, 30);
      stop_btn.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(stop_btn);
      panel.add(stop_btn);
      stop_btn.addActionListener(e -> {
         System.exit(0);
      });

      // FIFO
      JLabel lblFifo = new JLabel("FIFO");
      title(lblFifo, 20, 250, 230, 50, 15);

      FIFOtest = new TextArea();
      textBox(FIFOtest, 20, 180, 250, 200, 250);

      // JScrollPane scroll_fifo = new JScrollPane(FIFOtest);
      // scroll(scroll_fifo, 180, 250, 200, 250);

      // LRU
      JLabel lblLru = new JLabel("LRU");
      title(lblLru, 20, 490, 230, 50, 15);

      LRUtest = new TextArea();
      textBox(LRUtest, 20, 420, 250, 200, 250);

      // JScrollPane scroll_lru = new JScrollPane(LRUtest);
      // scroll(scroll_lru, 420, 250, 200, 250);

      // LFU
      JLabel lblLfu = new JLabel("LFU");
      title(lblLfu, 20, 730, 230, 50, 15);

      LFUtest = new TextArea();
      textBox(LFUtest, 20, 660, 250, 200, 250);

      // JScrollPane scroll_lfu = new JScrollPane(LFUtest);
      // scroll(scroll_lfu, 660, 250, 200, 250);

      //OPT
      JLabel lblOpt = new JLabel("OPT");
      title(lblOpt, 20, 970, 230, 50, 15);

      OPTtest = new TextArea();
      textBox(OPTtest, 20, 900, 250, 200, 250);

      // JScrollPane scroll_opt= new JScrollPane(OPTtest);
      // scroll(scroll_opt, 900, 250, 200, 250);

      JLabel label_11 = new JLabel("中断次数:");
      label_11.setBounds(35, 550, 100, 20);
      label_11.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(label_11);
      panel.add(label_11);

      fifo_interrupt_label = new JLabel("");
      fifo_interrupt_label.setBounds(220, 550, 100, 20);
      fifo_interrupt_label.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(fifo_interrupt_label);
      panel.add(fifo_interrupt_label);

      lru_interrupt_label = new JLabel("");
      lru_interrupt_label.setBounds(460, 550, 100, 20);
      lru_interrupt_label.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(lru_interrupt_label);
      panel.add(lru_interrupt_label);

      lfu_interrupt_label = new JLabel("");
      lfu_interrupt_label.setBounds(700, 550, 100, 20);
      lfu_interrupt_label.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(lfu_interrupt_label);
      panel.add(lfu_interrupt_label);

      opt_interrupt_label = new JLabel("");
      opt_interrupt_label.setBounds(940, 550, 100, 20);
      opt_interrupt_label.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(opt_interrupt_label);
      panel.add(opt_interrupt_label);

      JLabel label_12 = new JLabel("总时间:");
      label_12.setBounds(35, 600, 100, 20);
      label_12.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(label_12);
      panel.add(label_12);

      fifo_total_time_label = new JLabel("");
      fifo_total_time_label.setBounds(220, 600, 100, 20);
      fifo_total_time_label.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(fifo_total_time_label);
      panel.add(fifo_total_time_label);

      lru_total_time_label = new JLabel("");
      lru_total_time_label.setBounds(460, 600, 100, 20);
      lru_total_time_label.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(lru_total_time_label);
      panel.add(lru_total_time_label);

      lfu_total_time_label = new JLabel("");
      lfu_total_time_label.setBounds(700, 600, 100, 20);
      lfu_total_time_label.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(lfu_total_time_label);
      panel.add(lfu_total_time_label);

      opt_total_time_label = new JLabel("");
      opt_total_time_label.setBounds(940, 600, 100, 20);
      opt_total_time_label.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(opt_total_time_label);
      panel.add(opt_total_time_label);

      JLabel label_13 = new JLabel("平均时间:");
      label_13.setBounds(35, 650, 100, 20);
      label_13.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(label_13);
      panel.add(label_13);

      fifo_ave_time_label = new JLabel("");
      fifo_ave_time_label.setBounds(220, 650, 100, 20);
      fifo_ave_time_label.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(fifo_ave_time_label);
      panel.add(fifo_ave_time_label);

      lru_ave_time_label = new JLabel("");
      lru_ave_time_label.setBounds(460, 650, 100, 20);
      lru_ave_time_label.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(lru_ave_time_label);
      panel.add(lru_ave_time_label);

      lfu_ave_time_label = new JLabel("");
      lfu_ave_time_label.setBounds(700, 650, 100, 20);
      lfu_ave_time_label.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(lfu_ave_time_label);
      panel.add(lfu_ave_time_label);

      opt_ave_time_label = new JLabel("");
      opt_ave_time_label.setBounds(940, 650, 100, 20);
      opt_ave_time_label.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(opt_ave_time_label);
      panel.add(opt_ave_time_label);

      JLabel label_14 = new JLabel("缺页率:");
      label_14.setBounds(35, 700, 100, 20);
      label_14.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(label_14);
      panel.add(label_14);

      fifo_miss_page_label = new JLabel("");
      fifo_miss_page_label.setBounds(220, 700, 100, 20);
      fifo_miss_page_label.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(fifo_miss_page_label);
      panel.add(fifo_miss_page_label);

      lru_miss_page_label = new JLabel("");
      lru_miss_page_label.setBounds(460, 700, 100, 20);
      lru_miss_page_label.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(lru_miss_page_label);
      panel.add(lru_miss_page_label);

      lfu_miss_page_label = new JLabel("");
      lfu_miss_page_label.setBounds(700, 700, 100, 20);
      lfu_miss_page_label.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(lfu_miss_page_label);
      panel.add(lfu_miss_page_label);

      opt_miss_page_label = new JLabel("");
      opt_miss_page_label.setBounds(940, 700, 100, 20);
      opt_miss_page_label.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(opt_miss_page_label);
      panel.add(opt_miss_page_label);

      JButton save_btn = new JButton("保存");
      save_btn.setBounds(200, 760, 120, 30);
      save_btn.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(save_btn);
      panel.add(save_btn);
      save_btn.addActionListener(e -> {
         new Save();
      });

      JButton open_btn = new JButton("打开");
      open_btn.setBounds(500, 760, 120, 30);
      open_btn.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(open_btn);
      panel.add(open_btn);
      open_btn.addActionListener(e -> {
         new History();
      });

      JButton clear_btn = new JButton("清空");
      clear_btn.setBounds(800, 760, 120, 30);
      clear_btn.setFont(new Font("宋体", Font.PLAIN, 20));
      // frame.getContentPane().add(clear_btn);
      panel.add(clear_btn);
      clear_btn.addActionListener(e->{
         on_clear_btn_clicked();
         clear_parameter();
      });
   }

   /**
    * 四种算法标题
    * @param label
    * @param size
    * @param x
    * @param y
    * @param w
    * @param h
    */
   public void title(JLabel label, int size, int x, int y ,int w, int h) {
      label.setFont(new Font("宋体", Font.PLAIN, size));
      label.setBounds(x, y, w, h);
      // frame.getContentPane().add(label);
      panel.add(label);
   }

   /**
    * 四种算法运行结果显示框
    * @param textArea
    * @param size
    * @param x
    * @param y
    * @param w
    * @param h
    */
   public void textBox(TextArea textArea, int size, int x, int y ,int w, int h) {
      textArea.setFont(new Font("宋体", Font.PLAIN, size));
      textArea.setBackground(SystemColor.controlHighlight);
      textArea.setBounds(x, y, w, h);
      // frame.getContentPane().add(textArea);
      panel.add(textArea);
   }

   /**
    * 分别设置水平和垂直滚动条自动出现
    * @param scrollPane
    * @param x
    * @param y
    * @param w
    * @param h
    */
   public void scroll(JScrollPane scrollPane,int x, int y, int w, int h) {
      scrollPane.setLocation(x, y);
      scrollPane.setSize(w, h);

      scrollPane.setHorizontalScrollBarPolicy(
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
      scrollPane.setVerticalScrollBarPolicy(
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
      // frame.getContentPane().add(scrollPane);
      panel.add(scrollPane);
   }

   public void on_clear_btn_clicked() {
      // fifo.task[] = new int[fifo.taskSize];
      final int[] task = config.task;
      FIFOtest.setText("");
      fifo.fifo_lackpage = 0;
      fifo.fifo_ave_time=0;
      fifo.fifo_total_time=0;
      fifo.fifo_memory_page.clear();
      fifo.fifo_quick_table_page.clear();
      fifo.fifo_memory_page.clear();
      fifo_interrupt_label.setText("");
      fifo_miss_page_label.setText("");
      fifo_total_time_label.setText("");
      fifo_ave_time_label.setText("");
      LRUtest.setText("");
      lru.lru_lackpage = 0;
      lru.lru_ave_time=0;
      lru.lru_total_time=0;
      lru.lru_memory_page.clear();
      lru.lru_quick_table_page.clear();
      lru_interrupt_label.setText("");
      lru_miss_page_label.setText("");
      lru_total_time_label.setText("");
      lru_ave_time_label.setText("");
      LFUtest.setText("");
      lfu.lfu_lackpage = 0;
      lfu.lfu_ave_time=0;
      lfu.lfu_total_time=0;
      lfu.lfu_memory_page.clear();
      lfu.lfu_quick_table_page.clear();
      lfu_interrupt_label.setText("");
      lfu_miss_page_label.setText("");
      lfu_total_time_label.setText("");
      lfu_ave_time_label.setText("");
      OPTtest.setText("");
      opt.opt_lackpage = 0;
      opt.opt_ave_time=0;
      opt.opt_total_time=0;
      opt.opt_memory_page.clear();
      opt.opt_quick_table_page.clear();
      opt_interrupt_label.setText("");
      opt_miss_page_label.setText("");
      opt_total_time_label.setText("");
      opt_ave_time_label.setText("");

   }

   public static void on_quick_table_check_clicked(boolean checked) {
      if (checked)
         quick_table_num_edit.setEnabled(true);
      else
         quick_table_num_edit.setEnabled(false);
   }

   public static void clear_parameter() {
      memory_num_edit.setText("");
      taskSize_edit.setText("");
      taskSize_low_edit.setText("");
      taskSize_high_edit.setText("");
      task_low_edit.setText("");
      task_high_edit.setText("");
      task_edit.setText("");
      quick_table_num_edit.setText("");
      memory_access_edit.setText("");
      quick_table_access_edit.setText("");
      miss_page_interrupt_edit.setText("");
      run_time_edit.setText("");
      quick_table_check.setSelected(false);
      quick_table_num_edit.setEnabled(false);
   }

   public static void main(String[] args) {
      Page window = new Page();
      window.frame.setVisible(true);
   }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/126774.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

JDK17升级之路:JCE cannot authenticate the provider BC问题

问题的产生 报错代码运行环境 JDK&#xff1a;Oracle JDK17 CentOS7.8 这个问题刚拿到比较棘手。原因是本地windows是OK的&#xff0c;centos上是不成功的&#xff0c;报了下面的错误&#xff1a; Caused by: java.lang.SecurityException: JCE cannot authenticate the provi…

论文阅读 DeepGCNs: Can GCNs Go as Deep as CNNs?

DeepGCNs: Can GCNs Go as Deep as CNNs?绪论1、介绍2、相关工作3、方法3.1、图神经网络的表针学习3.2、图神经网络的残差结构3.3、图神经网络的密集连接3.4、图神经网络的扩张性聚集绪论 CNN很强&#xff0c;但不能正确解决非欧几里得数据的问题&#xff0c;图卷积网络&…

YOLO-V5 系列算法和代码解析(五)—— 损失函数

文章目录基本简介调试准备损失函数基本简介 损失函数是神经网络的重要组成部分&#xff0c;用于评估网络的预测值和真实值的差异度。根据偏差的大小&#xff0c;反向调整网络的训练参数&#xff0c;迭代优化使得损失尽量小&#xff0c;也就得到最优的网络参数。 调试准备 debu…

Go-学生教务管理系统【无界面 / 离线版】(一)

【Go】学生教务管理系统&#xff08;无界面 / 离线版&#xff09;&#xff08;一&#xff09;Ⅰ. 程序说明一、博客日期二、引言Ⅱ. 版权声明Ⅲ. 开发环境一、开发配置二、开发工具Ⅳ. 效果演示一、工程结构&#xff08;一&#xff09;目录结构&#xff08;二&#xff09;目录说…

【Ctfer训练计划】——(六)

作者名&#xff1a;Demo不是emo 主页面链接&#xff1a;主页传送门 创作初心&#xff1a;舞台再大&#xff0c;你不上台&#xff0c;永远是观众&#xff0c;没人会关心你努不努力&#xff0c;摔的痛不痛&#xff0c;他们只会看你最后站在什么位置&#xff0c;然后羡慕或鄙夷座…

Springboot启动之自定义run方法

前言 之前分析的Springboot启动过程的源码分析中给自己留了一个扩展作业&#xff1a;执行自定义的run方法&#xff0c;此方法在B.7、调用运行器简单分析过&#xff0c;今天咱们就自定义一个Run方法试试。 一、实现自定义的run方法 由于java中的接口可以多实现&#xff0c;所以…

IOS----TangramKit 布局框架

文章目录系统结构CocoaPods安装举例下面一个应用场景:布局线性布局TGLinearLayout相对布局TGRelativeLayout框架布局TGFrameLayout表格布局TGTableLayout流式布局TGFlowLayout浮动布局TGFloatLayout路径布局MyPathLayoutgithub: https://github.com/youngsoft/TangramKit/blob…

day32【代码随想录】回溯之N皇后、N皇后||、解数独、有效的数独

文章目录前言一、N皇后&#xff08;力扣51&#xff09;二、N皇后||&#xff08;力扣52&#xff09;三、解数独&#xff08;力扣37&#xff09;四、有效的数独&#xff08;力扣36&#xff09;前言 1、N皇后、 2、N皇后||、 3、解数独、 4、有效的数独 一、N皇后&#xff08;力扣…

材料表征仪器:慢正电子束谱仪最全知识讲解

1 引言 21世纪科学的发展将是微观与宏观的相互渗透与密切结合。凝聚态物理、材料科学等的研究&#xff0c;将由现在的宏观统计方法&#xff08;包括宏观量子统计&#xff09;深入发展到物质的原子层次物性研究&#xff0c;微观粒子&#xff08;颗粒、孔隙&#xff09;的量子效…

求最大公约数,求阶乘,求n个n相乘的末两位数(Python)

问题 AN: 41.求最大公约数 题目描述 对于求两个正整数m&#xff0c;n的最大公约数可以用do-while实现 输入 输入两个正整数m&#xff0c;n 输出 最大公约数 样例输入 1 2 样例输出 1 a,b map(int,input().split()) if a<b:a,b b,a#python很方便的交换操作 #适应判断不带…

MySQL复制技术方案——异步复制配置

为MySQL服务器配置复制非常简单。但由于场景不同&#xff0c;基本的步骤还是有所差异。最基本的场景是新安装的主库和备库&#xff0c;总的来说分为以下几步∶ 1. 配置复制 为MySQL服务器配置复制非常简单。但由于场景不同&#xff0c;基本的步骤还是有所差异。最基本的场景是…

HTML5 Canvas

文章目录HTML5 Canvas概述Canvas元素使用绘制直线画2条直线用直线画三角形用直线画矩形绘制矩形描边矩形填充矩形混合使用rect()清空矩形区域清空画布绘制多边形画箭头画正三角形绘制圆形HTML5 Canvas 概述 HTML5新增了一个Canvas元素&#xff0c;我们常说的Canvas技术&#…

【LeetCode】填充每个节点的下一个右侧节点指针 [M](二叉树遍历)

116. 填充每个节点的下一个右侧节点指针 - 力扣&#xff08;LeetCode&#xff09; 一、题目 给定一个 完美二叉树 &#xff0c;其所有叶子节点都在同一层&#xff0c;每个父节点都有两个子节点。二叉树定义如下&#xff1a; struct Node { int val; Node *left; Node *…

通过webpack解决浏览器兼容问题

前言 很多面试时都会问到关于浏览器兼容问题&#xff0c;正好最近在看webpack打包&#xff0c;那就在这里记录一下我们如何通过webpack来实现兼容。 需求 要知道我们到底需要兼容那些浏览器&#xff0c;在这里就需要用到browserlist来配置需要兼容的浏览器版本并告诉webpack…

Jenkins自动部署项目

目录 1.安装插件 2.配置 本文只讲解通过插件来自动部署项目&#xff0c;Jenkins的安装可以看博主的另一篇文章&#xff0c;绝对保姆级&#xff0c;简洁丝滑的安装教程&#xff1a; jenkins下载安装__BugMan的博客-CSDN博客 1.安装插件 目前业内常用的解决方法是使用publish…

程序员必备十大网站

窝窝整理了十大程序猿必备网站&#xff0c;涵盖了开源平台、搜索引擎、免费的精品课程&#xff0c;包括让你头疼的BUG、算法等。偷偷告诉你&#xff0c;还有帮你拿到心仪的 offer&#xff01; 一&#xff0c;海量的资源平台 十大网站榜首 &#xff1a;GitHub — 开发者极其重…

图查询语言 nGQL 简明教程 vol.01 快速入门

本文旨在让新手快速了解 nGQL&#xff0c;掌握方向&#xff0c;之后可以脚踩在地上借助文档写出任何心中的 NebulaGraph 图查询。 视频 本教程的视频版在B站这里。 准备工作 在正式开始 nGQL 实操之前&#xff0c;记得先看过文档「快速入门流程」&#xff0c;部署、连接过 …

《小强升职记》读后感

为什么平庸&#xff1f; 成功的人每天都在忙碌&#xff0c;平庸的人每天也在忙碌&#xff0c;而时间对每个人来说是绝对公平的&#xff0c;那么&#xff0c;两者之间的差距到底是如何产生的呢? 第一&#xff0c;在这个人生的关键时期&#xff0c;我们被迫完成角色的转变。 …

C语言 字符函数和字符串函数及模拟实现

上图注意内容 代码解释如下 int main() {if (my_strlen("abc") - my_strlen("abcdef") > 0){printf(">\n");}else{printf("<\n");}return 0; }my_strlen int my_strlen(const char* str) {int count 0;//计数器assert(str…

Springboot AOP切面

文章目录SpringBoot Aop切面(Aop)一、什么是切面二、切面的用途三、AOP切面常用注解四、详细内容1、切面&#xff08;Aspect&#xff09;2、连接点&#xff08;Joinpoint&#xff09;3、通知&#xff08;Advice&#xff09;4.切入点&#xff08;Pointcut&#xff09;五、代码操…