操作系统课程设计银行家算法和页面置换算法.pdf
《操作系统课程设计银行家算法和页面置换算法.pdf》由会员分享,可在线阅读,更多相关《操作系统课程设计银行家算法和页面置换算法.pdf(28页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、1/28 XX 工程学院 操作系统课程设计说明书 题目操作系统银行家算法和页面置换算法班 级软件 101 学 生 姓 名 X 洋 学 号 202100320 2/28 课设截图:3/28 4/28 5/28 6/28 7/28 8/28 9/28 源代码:3 个类:MainFrame.java:importjava.awt.Font;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.ButtonGroup;importjavax.swing.utton;importjav
2、ax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JPanel;importjavax.swing.JRadioButton;importjavax.swing.UIManager;importjavax.swing.UIManager.LookAndFeelInfo;public class MainFrame extends JFrame implements ActionListener /*/private static final long serialVersionUID=1L;privateJPanel pane
3、l1,panel2,panel3;privateJLabel label1,label2;privateutton button1;privateJRadioButton b1,b2;publicMainFrame()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 JP
4、anel();Font f=new Font(楷体,1,60);Font f1=new Font(宋体,3,30);Font f2=new Font(幼圆,1,15);10/28 label1=new JLabel(操作系统课程设计);label1.setFont(f);label2=new JLabel(算法模拟题目:);label2.setFont(f1);panel1.add(label1);panel2.add(label2);ButtonGroupbgroup=new ButtonGroup();b1=new JRadioButton(银行家算法,true);b1.setFont(f
5、1);bgroup.add(b1);b2=new JRadioButton(页面置换算法);b2.setFont(f1);bgroup.add(b2);panel2.add(b1);panel2.add(b2);button1=new utton(开始演示);button1.setFont(f2);button1.addActionListener(this);panel3.add(button1);this.add(panel1);this.add(panel2);this.add(panel3);this.setDefaultCloseOperation(EXIT_ON_CLOSE);th
6、is.setVisible(true);public void actionPerformed(ActionEvent e)if(e.getSource()=button1)if(b1.isSelected()new Banker();if(b2.isSelected()newYemian();11/28 public static void main(String args)try for(LookAndFeelInfo info:UIManager.getInstalledLookAndFeels()if(Nimbus.equals(info.getName()UIManager.setL
7、ookAndFeel(info.getClassName();break;catch(Exception e1)newMainFrame();Banker.java:importjava.awt.*;importjava.awt.event.*;importjava.util.ArrayList;importjavax.swing.*;importjavax.swing.table.DefaultTableCellRenderer;importjavax.swing.table.DefaultTableModel;public class Banker extends JFrame imple
8、ments ActionListener /*/private static final long serialVersionUID=1L;privateJTable 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;privateutton b1,b2,b3,b4,b5,b6;private TextField text01,text02,text03,text04,text05,tex
9、t06;/编辑框 private JTextField text1,text2,text3,text4,text5;/进程组的数据 DefaultTableModel tablemodel,tablemodel1;ArrayList list;12/28 int claim,allocation,need;int available;int request,temavail,release;boolean possible;intm,n,index=0;public Banker()super(银行家算法模拟);p0=new JPanel();p1=new JPanel();p11=new J
10、Panel();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.setLayout(new GridLayout(4,1);p3.setLayout(new GridLayout(4,1);p1.add(p11
11、);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);13/28 t1=new JLabel(进程数);t2=new JLabel(资源数);t3=new JLabel(进程号);t4=new JLabel(已分配资资源:);t5=new JLabel(资源最大需求:);t6=new JLabel(可用资源:);t7=new JLabel(请求资源进程号);t8=new
12、 JLabel(请求资源为);t9=new JLabel(释放资源);t10=new JLabel(安全序列);t11=new JLabel(释放资源进程号);b1=new utton(确定);b2=new utton(添加);b3=new utton(确定);b4=new utton(请求);b5=new utton(开始检测);b6=new utton(释放);text1=new JTextField6;text2=new JTextField6;text3=new JTextField6;text4=new JTextField6;text5=new JTextField6;for(in
13、t 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);text03=new TextField(4);text04=new TextField(4);text05=new TextField(4);text06=new TextField(20);String columnNames
14、1=进程号,allocation,claim,need,available;tablemodel=new DefaultTableModel(columnNames1,0);table1=new JTable(tablemodel);table1.setPreferredScrollableViewportSize(new Dimension(700,200);table1.setRowHeight(20);14/28 table1.doLayout();DefaultTableCellRenderer r=new DefaultTableCellRenderer();r.setHorizon
15、talAlignment(JLabel.CENTER);table1.setDefaultRenderer(Object.class,r);JScrollPane pane1=new JScrollPane(table1);p11.add(t1);p11.add(text01);p11.add(t2);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.
16、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;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);15/28 String columnNames2=进程号,c
17、urrentavail,need,allocation,curr.+allo.,possible;tablemodel1=new DefaultTableModel(columnNames2,0);table2=new JTable(tablemodel1);table2.setPreferredScrollableViewportSize(new Dimension(700,200);table2.setRowHeight(20);table2.doLayout();DefaultTableCellRenderer r1=new DefaultTableCellRenderer();r1.s
18、etHorizontalAlignment(JLabel.CENTER);table2.setDefaultRenderer(Object.class,r1);JScrollPane pane2=new JScrollPane(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
19、.addActionListener(this);p0.setBackground(Color.lightGray);list=new ArrayList();this.setContentPane(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(
20、text01.getText();catch(NumberFormatException e1)JOptionPane.showMessageDialog(this,进程数不能为空);return;try 16/28 n=Integer.parseInt(text02.getText();catch(NumberFormatException e1)JOptionPane.showMessageDialog(this,资源数不能为空);return;claim=new intmn;need=new intmn;allocation=new intmn;available=new intn;re
21、quest=new intn;release=new intn;for(int i=0;i5-n;i+)p13.remove(text14-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
22、.updateUI();temavail=new intn;String str=,;for(int i=0;i=m)JOptionPane.showMessageDialog(this,进程个数已满);17/28 return;try for(int j=0;jn;j+)allocationindexj=Integer.parseInt(text1j.getText();claimindexj=Integer.parseInt(text2j.getText();needindexj=claimindexj-allocationindexj;catch(Exception f)nameinde
23、x=P+index;String strd=,;strd0=nameindex;for(int j=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=availab
24、lei;catch(NumberFormatException f)18/28 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.g
25、etSource()=b4)for(int i=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 f
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 操作系统 课程设计 银行家 算法 页面 置换
限制150内