操作系统课程设计银行家算法和页面置换算法(29页DOC).docx

上传人:ahu****ng1 文档编号:59031987 上传时间:2022-11-09 格式:DOCX 页数:30 大小:624.86KB
返回 下载 相关 举报
操作系统课程设计银行家算法和页面置换算法(29页DOC).docx_第1页
第1页 / 共30页
操作系统课程设计银行家算法和页面置换算法(29页DOC).docx_第2页
第2页 / 共30页
点击查看更多>>
资源描述

《操作系统课程设计银行家算法和页面置换算法(29页DOC).docx》由会员分享,可在线阅读,更多相关《操作系统课程设计银行家算法和页面置换算法(29页DOC).docx(30页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

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.sw

2、ing.JLabel;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;

3、 private 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=ne

4、w JPanel(); 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);

5、b1.setFont(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.setDefaultClos

6、eOperation(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.equal

7、s(info.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;

8、public 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; pr

9、ivate 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()

10、 super(银行家算法模拟); 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.

11、setLayout(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 JLab

12、el(已分配资资源:); 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

13、=new JTextField6; 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 TextF

14、ield(4); 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 D

15、imension(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);

16、p11.add(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

17、i=0;i5;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 (tabl

18、emodel1); 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 JScro

19、llPane (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.setCo

20、ntentPane (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(

21、this,进程数不能为空);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(t

22、ext14-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(i

23、nt i=0;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=

24、0;jn;j+)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)

25、 JOptionPane.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=

26、0;in;i+) 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.

27、showMessageDialog(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.si

28、ze()=m)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.s

29、etValueAt(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

30、 k=0;kn;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, 系统处于不安全状态,不能分配资源!

31、); return; 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.showMe

32、ssageDialog(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.

33、GridLayout;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;/页框最大个

34、数private 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;/页框private JLabel processLabel;private JLabel makePLabel;private JLabel makeMLabel;private JTextField processField;private JTextField memeryField;p

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 管理文献 > 管理制度

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

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁