操作系统课程设计银行家算法和面置换算法

上传人:水****8 文档编号:161327864 上传时间:2022-10-13 格式:DOCX 页数:31 大小:9.47MB
收藏 版权申诉 举报 下载
操作系统课程设计银行家算法和面置换算法_第1页
第1页 / 共31页
操作系统课程设计银行家算法和面置换算法_第2页
第2页 / 共31页
操作系统课程设计银行家算法和面置换算法_第3页
第3页 / 共31页
资源描述:

《操作系统课程设计银行家算法和面置换算法》由会员分享,可在线阅读,更多相关《操作系统课程设计银行家算法和面置换算法(31页珍藏版)》请在装配图网上搜索。

1、 南京工程学院操作系统课程设计说明书题 目 操作系统银行家算法和页面置换算法 班 级 软件101 学 生 姓 名 刘 洋 学 号 202100320 课设截图:源代码:3个类:MainFrame.java:import java.awt.Font;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.ButtonGroup;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JL

2、abel;import javax.swing.JPanel;import javax.swing.JRadioButton;import javax.swing.UIManager;import javax.swing.UIManager.LookAndFeelInfo;public class MainFrame extends JFrame implements ActionListener /* * */ private static final long serialVersionUID = 1L; private JPanel panel1,panel2,panel3; priva

3、te JLabel label1,label2; private JButton button1; private JRadioButton b1,b2; public MainFrame() super(操作系统课程设计); this.setBounds(300, 150, 800, 500); this.setBackground(java.awt.Color.LIGHT_GRAY); this.setLayout(new java.awt.GridLayout(3, 1); panel1=new JPanel(); panel2=new JPanel(); panel3=new JPan

4、el(); Font f =new Font(楷体,1,60); Font f1=new Font(宋体,3,30); Font f2=new Font(幼圆,1,15); label1=new JLabel(操作系统课程设计); label1.setFont(f); label2=new JLabel(算法模拟题目:); label2.setFont(f1); panel1.add(label1); panel2.add(label2); ButtonGroup bgroup=new ButtonGroup(); b1=new JRadioButton(银行家算法,true); b1.set

5、Font(f1); bgroup.add(b1); b2=new JRadioButton(页面置换算法); b2.setFont(f1); bgroup.add(b2); panel2.add(b1); panel2.add(b2); button1=new JButton(开始演示); button1.setFont(f2); button1.addActionListener(this); panel3.add(button1); this.add(panel1); this.add(panel2); this.add(panel3); this.setDefaultCloseOpera

6、tion(EXIT_ON_CLOSE); this.setVisible(true); public void actionPerformed(ActionEvent e) if(e.getSource()=button1)if(b1.isSelected() new Banker();if(b2.isSelected()new Yemian();public static void main (String args) tryfor(LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()if(Nimbus.equals(info

7、.getName()UIManager.setLookAndFeel(info.getClassName();break;catch(Exception e1) new MainFrame(); Banker.java:import java.awt.*;import java.awt.event.*;import java.util.ArrayList;import javax.swing.*;import javax.swing.table.DefaultTableCellRenderer;import javax.swing.table.DefaultTableModel; public

8、 class Banker extends JFrame implements ActionListener /* * */private static final long serialVersionUID = 1L;private JTable table1,table2; private JPanel p0,p1,p11,p12,p13,p14,p2,p3,p31,p32,p33,p34,p4,p5; private JLabel t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11; private JButton b1,b2,b3,b4,b5,b6; private

9、TextField text01,text02,text03,text04,text05,text06;/编辑框 private JTextField text1,text2,text3,text4,text5;/进程组的数据 DefaultTableModel tablemodel,tablemodel1; ArrayList list ; int claim,allocation,need; int available;int request,temavail,release; boolean possible; int m,n,index=0; public Banker() super

10、(银行家算法模拟); p0=new JPanel(); p1=new JPanel(); p11=new JPanel(); p12=new JPanel(); p13=new JPanel(); p14=new JPanel(); p2=new JPanel(); p3=new JPanel(); p31=new JPanel(); p32=new JPanel(); p33=new JPanel(); p34=new JPanel(); p4=new JPanel(); p5=new JPanel(); p0.setLayout(new GridLayout(5,1); p1.setLay

11、out(new GridLayout(4,1); p3.setLayout(new GridLayout(4,1); p1.add(p11); p1.add(p12); p1.add(p13); p1.add(p14); p3.add(p31); p3.add(p32); p3.add(p33); p3.add(p34); p0.add(p1); p0.add(p2); p0.add(p3); p0.add(p4); p0.add(p5); t1=new JLabel(进程数); t2=new JLabel(资源数); t3=new JLabel(进程号); t4=new JLabel(已分配

12、资资源:); t5=new JLabel(资源最大需求:); t6=new JLabel(可用资源:); t7=new JLabel(请求资源进程号); t8=new JLabel(请求资源为); t9=new JLabel(释放资源); t10=new JLabel(平安序列); t11=new JLabel(释放资源进程号); b1=new JButton(确定); b2=new JButton(添加); b3=new JButton(确定); b4=new JButton(请求); b5=new JButton(开始检测); b6=new JButton(释放); text1=new J

13、TextField6; text2=new JTextField6; text3=new JTextField6; text4=new JTextField6; text5=new JTextField6; for(int i=0;i5;i+) text1i=new JTextField(4); text2i=new JTextField(4); text3i=new JTextField(4); text4i=new JTextField(4); text5i=new JTextField(4); text01=new TextField(4); text02=new TextField(4

14、); text03=new TextField(4); text04=new TextField(4); text05=new TextField(4); text06=new TextField(20); String columnNames1= 进程号, allocation,claim,need,available; tablemodel=new DefaultTableModel(columnNames1,0); table1 = new JTable (tablemodel); table1.setPreferredScrollableViewportSize(new Dimensi

15、on(700, 200); table1.setRowHeight (20); table1.doLayout (); DefaultTableCellRenderer r = new DefaultTableCellRenderer(); r.setHorizontalAlignment(JLabel.CENTER); table1.setDefaultRenderer(Object.class,r); JScrollPane pane1 = new JScrollPane (table1); p11.add(t1); p11.add(text01); p11.add(t2); p11.ad

16、d(text02); p11.add(b1); p12.add(t3); p12.add(text03); p12.add(b2); p13.add(t4); for(int i=0;i5;i+) p13.add(text1i); p14.add(t5); for(int i=0;i5;i+) p14.add(text2i); p2.add (pane1); p31.add(t6); for(int i=0;i5;i+) p31.add(text3i); p31.add(b3); p32.add(t7); p32.add(text04); p32.add(t8); for(int i=0;i5

17、;i+) p32.add(text4i); p32.add(b4); p33.add(t11); p33.add(text05); p33.add(t9); for(int i=0;i5;i+) p33.add(text5i); p33.add(b6); p34.add(b5); String columnNames2= 进程号, currentavail,need,allocation,curr.+allo.,possible; tablemodel1=new DefaultTableModel(columnNames2,0); table2 = new JTable (tablemodel

18、1); table2.setPreferredScrollableViewportSize(new Dimension(700, 200); table2.setRowHeight (20); table2.doLayout (); DefaultTableCellRenderer r1 = new DefaultTableCellRenderer(); r1.setHorizontalAlignment(JLabel.CENTER); table2.setDefaultRenderer(Object.class,r1); JScrollPane pane2 = new JScrollPane

19、 (table2); p4.add (pane2); p5.add(t10); p5.add(text06); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); b4.addActionListener(this); b5.addActionListener(this); b6.addActionListener(this); p0.setBackground (Color.lightGray); list = new ArrayList(); this.setContentP

20、ane (p0); this.setVisible(true); this.pack(); this.setLocation(300, 10); this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); public void actionPerformed(ActionEvent e) if(e.getSource()=b1) try m= Integer.parseInt(text01.getText(); catch(NumberFormatException e1) JOptionPane.showMessageDialog(this,进

21、程数不能为空);return; try n = Integer.parseInt(text02.getText(); catch(NumberFormatException e1) JOptionPane.showMessageDialog(this,资源数不能为空);return; claim= new intmn; need=new intmn; allocation = new intmn; available = new intn; request = new intn; release=new intn; for(int i=0;i5-n;i+) p13.remove(text14-

22、i); p13.updateUI(); for(int i=0;i5-n;i+) p14.remove(text24-i); p14.updateUI(); for(int i=0;i5-n;i+) p31.remove(text34-i); p31.updateUI(); for(int i=0;i5-n;i+) p32.remove(text44-i); p32.updateUI(); for(int i=0;i5-n;i+) p33.remove(text54-i); p33.updateUI(); temavail=new intn; String str=,; for(int i=0

23、;i=m) JOptionPane.showMessageDialog(this,进程个数已满);return;tryfor(int j=0;jn;j+) allocationindexj=Integer.parseInt(text1j.getText();claimindexj=Integer.parseInt(text2j.getText();needindexj=claimindexj-allocationindexj; catch(Exception f)nameindex=P+index; String strd=,;strd0=nameindex; for(int j=0;jn;j

24、+)strd1+=allocationindexj+ ; for(int j=0;jn;j+) strd2+=claimindexj+ ; for(int j=0;jn;j+) strd3+=needindexj+ ; strd4= ; tablemodel.addRow(strd); index+; if(e.getSource()=b3) try for(int i=0;in;i+) availablei=Integer.parseInt(text3i.getText(); temavaili=availablei; catch(NumberFormatException f) JOpti

25、onPane.showMessageDialog(this,可用资源不能为空,请重新输入);return; String str=; for(int i=0;in;i+) str+=availablei+ ; tablemodel.setValueAt(str, 0, 4); if(e.getSource()=b5) list.clear(); safe(); for(int i=0;itable1.getRowCount();i+) tablemodel1.removeRow(0); update_table2(); if(e.getSource()=b4) for(int i=0;in;i

26、+) try requesti=Integer.parseInt(text4i.getText(); catch(NumberFormatException f1) JOptionPane.showMessageDialog(this,请求资源不能 为空,请重新输入);return; requestresource(); if(e.getSource()=b6) for(int i=0;in;i+) try releasei=Integer.parseInt(text5i.getText(); catch(NumberFormatException f1) JOptionPane.showMe

27、ssageDialog(this,释放资源不能 为空,请重新输入); return; releaseresource(); private boolean safe() boolean result =false;for(int i=0;im;i+) int j=0; while(jm) boolean can =true; for(int k=0;kavailablek)can=false; if(can&!list.contains(Object)j) list.add(j); for(int k=0;k=m) break; if(i=m-1)break; if(list.size()=m

28、)for(int k=0;kn;k+) availablek=temavailk;result=true;return result; public void update_table1() int index1=Integer.parseInt(text04.getText(); String str=,; for(int k=0;kn;k+) str0+=allocationindex1k+ ; tablemodel.setValueAt(str0, index1, 1); for(int k=0;kn;k+) str1+=needindex1k+ ; tablemodel.setValu

29、eAt(str1, index1, 3); for(int k=0;kn;k+) str2+=availablek+ ; tablemodel.setValueAt(str2, 0, 4); public void update_table2() if(safe() String temp = ; for(Integer x:list) temp += (P+x + ,); String str=,; str0=P+x; for(int k=0;kn;k+) str1+=availablek+ ; for(int k=0;kn;k+) str2+=needxk+ ; for(int k=0;k

30、n;k+) str3+=allocationxk+ ; for(int k=0;kn;k+) availablek+=allocationxk; for(int k=0;kn;k+) str4+=availablek+ ; str5=True; tablemodel1.addRow(str); for(int k=0;kn;k+) availablek=temavailk; text06.setText(temp); else text06.setText(不存在平安序列); JOptionPane.showMessageDialog(this, 系统处于不平安状态,不能分配资源!); ret

31、urn; public void requestresource() int index1=Integer.parseInt(text04.getText(); for(int i=0;in;i+) if(requesti=needindex1i&requesti=availablei) temavaili-=requesti; allocationindex1i+=requesti; needindex1i-=requesti; if(safe() update_table1(); else temavaili+=requesti; else JOptionPane.showMessageD

32、ialog(this, 系统资源缺乏,申请被拒绝!); return; public void releaseresource() int index2=Integer.parseInt(text05.getText(); for(int i=0;in;i+) availablei+= releasei; temavaili+=releasei; allocationindex2i-=releasei; needindex2i+=releasei; update_table1(); Yemian.java:import java.awt.Color;import java.awt.GridLa

33、yout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.ArrayList;import java.util.LinkedList;import javax.swing.*;public class Yemian extends JFrame implements ActionListener/* * */private static final long serialVersionUID = 1L;private int mSIZE=20;/页框最大个数priva

34、te static int pSIZE=20;/页面最大个数private static int process=new intpSIZE;/随机产生的页面走向static String memString=;private JButton demoFIFO;private JButton demoLRU;private JComboBox produce;/随机产生或输入数据private JTextArea fifoArea;private JTextArea lruArea;private JButton makeProcess;/页面private JButton makememery

35、;/页框private JLabel processLabel;private JLabel makePLabel;private JLabel makeMLabel;private JTextField processField;private JTextField memeryField;private JPanel producePanel;private JPanel inputmemery;private JPanel inputprocess;private JPanel lruPanel;private JPanel fifoPanel;private JScrollPane l

36、ruScrollPane;private JScrollPane fifoScrollPane;public Yemian()super(页面置换算法 FIFO、LRU);demoFIFO=new JButton(演示FIFO);demoLRU=new JButton(演示LRU);String xz=随机页面序列,输入页面序列;produce=new JComboBox(xz);processLabel=new JLabel(页号序列);makememery=new JButton(确定页框个数);makeMLabel=new JLabel(请输入页框个数:);makeProcess=new

37、 JButton(确定页面个数);makePLabel=new JLabel(请输入页面个数:);producePanel=new JPanel(new GridLayout(2,1);producePanel.setBackground(Color.YELLOW);inputmemery=new JPanel();inputmemery.setLayout(null);inputmemery.setBackground(Color.GREEN);inputprocess=new JPanel();inputprocess.setLayout(null);inputprocess.setBac

38、kground(Color.MAGENTA);lruPanel=new JPanel();lruPanel.setLayout(null);lruPanel.setBackground(Color.PINK);fifoPanel=new JPanel();fifoPanel.setLayout(null);fifoPanel.setBackground(Color.ORANGE);processField=new JTextField();memeryField=new JTextField();fifoArea=new JTextArea();lruArea=new JTextArea();

39、fifoScrollPane=new JScrollPane(fifoArea);lruScrollPane=new JScrollPane(lruArea);this.setLayout(null);this.setBackground(Color.BLUE);producePanel.setBounds(5, 5, 706, 90);inputmemery.setBounds(5, 95, 200, 220);inputprocess.setBounds(5, 320, 200, 220);fifoPanel.setBounds(210, 95, 210, 450);lruPanel.se

40、tBounds(500, 95, 210, 450);this.add(producePanel);this.add(inputmemery);this.add(inputprocess);this.add(fifoPanel);this.add(lruPanel);makeMLabel.setBounds(30, 15, 170, 45);memeryField.setBounds(30, 85, 150, 40);makememery.setBounds(30, 140, 150, 45);inputmemery.add(makememery);inputmemery.add(memery

41、Field);inputmemery.add(makeMLabel);makePLabel.setBounds(30, 15, 170, 45);processField.setBounds(30, 85, 150, 40);makeProcess.setBounds(30, 140, 150, 45);inputprocess.add(makePLabel);inputprocess.add(processField);inputprocess.add(makeProcess);produce.setBounds(150, 25, 150, 45);demoFIFO.setBounds(60

42、, 385, 90, 45);demoLRU.setBounds(60, 385, 90, 45);processLabel.setBounds(320, 10, 500, 60);fifoScrollPane.setBounds(15, 30, 180, 320);fifoPanel.add(fifoScrollPane);fifoPanel.add(demoFIFO);lruScrollPane.setBounds(15, 30, 180, 320);lruPanel.add(lruScrollPane);lruPanel.add(demoLRU);producePanel.add(pro

43、duce);producePanel.add(processLabel);produce.addActionListener(this);demoFIFO.addActionListener(this);demoLRU.addActionListener(this);makememery.addActionListener(this);makeProcess.addActionListener(this);this.setBounds(300, 50, 750, 600);this.setVisible(true);this.setDefaultCloseOperation(JFrame.HI

44、DE_ON_CLOSE);public void actionPerformed(ActionEvent e)if (e.getSource()=produce)if(produce.getSelectedItem().toString()=随机页面序列)build();fifoArea.setText();lruArea.setText();inputprocess.add(makePLabel);inputprocess.add(processField);inputprocess.add(makeProcess);inputprocess.updateUI();if(produce.ge

45、tSelectedItem().toString()=输入页面序列)inputprocess.remove(makeProcess);inputprocess.remove(makePLabel);inputprocess.remove(processField);inputprocess.updateUI();String str=JOptionPane.showInputDialog(this, 请输入页面序列(格式为:1,2,3,.);if(str=null)JOptionPane.showMessageDialog(this,无效值);return;/System.out.printl

46、n(str);String s=str.split(,);ArrayList list=new ArrayList();tryfor(int i=0;is.length;i+)list.add(Integer.parseInt(si);catch(NumberFormatException f)JOptionPane.showMessageDialog(this, 输入数字格式不正确); process=new intlist.size(); String string=;for(int i=0;iprocess.length;i+)string=string+list.get(i)+ ;pr

47、ocessi=list.get(i);for(int i=0;iprocess.length;i+)/System.out.println( +processi);pSIZE=process.length;processLabel.setText(string);if (e.getSource()=demoFIFO)FIFO();if (e.getSource()=demoLRU)LRU();if (e.getSource()=makememery) String s1=memeryField.getText();if(s1.trim().equals()JOptionPane.showMes

48、sageDialog(this, 页框个数不能为空);return; mSIZE=Integer.parseInt(memeryField.getText();memeryField.setText();if (e.getSource()=makeProcess)String s2=processField.getText();if(s2.trim().equals()JOptionPane.showMessageDialog(this, 页面个数不能为空);return;pSIZE=Integer.parseInt(processField.getText();processField.setText();public void setLabel(JLabel lab

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!