




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、源代码:第一个类:divDTOpublic class divDTOprivate int divBase;private int length;private int divFlag;public divDTO(int divBase,int length,int divFlag)this.divBase = divBase;this.divFlag = divFlag;this.length = length;public divDTO()public void setDivBase(int base)this.divBase = base;public int getDivBase()r
2、eturn this.divBase;public void setLength(int length)this.length = length;public int getLength()return this.length;public void setDivFlag(int flag)this.divFlag = flag;public int getDivFalg()return this.divFlag;2.第二个类:PcbDTOpublic class PcbDTOstatic final int Running = 1;static final int Ready = 2;sta
3、tic final int Waiting = 3;private String processName;private int runTime;private int prority;private int processState;private int base;private int limit;private int pcbFlag;public PcbDTO(String name, int time,int pro,int base,int limit)cessName = name;this.runTime = time;rity = pro;t
4、cessState = 0;this.limit = limit;this.base = base;public PcbDTO()this.pcbFlag = 0;public void setProcessName(String name)cessName = name;public String getProcessName()return processName;public void setRunTime(int time)this.runTime = time;public int getRunTime()return this.runTime;publ
5、ic void setPrority(int prority)rity = prority;public int getPrority()return rity;public void setProcessState(int state)cessState = state;public String getProcessState()String s = new String();if(cessState = 1)s = "running"else if(cessState = 2)s = &q
6、uot;ready"else if(cessState = 3)s = "waiting"return s;public int getBase()return this.base;public void setBase(int base)this.base = base;public void setLimit(int limit)this.limit = limit;public int getLimit()return this.limit;第三个类:主类import javax.swing.*;import java.util.*;impo
7、rt java.awt.*;import java.awt.event.*;import javax.swing.event.*;public class MainFrameprivate JList readyList;private JList waitingList;private JList jobList;private JButton susButton;private JButton relaxButton;private JButton startButton;private JButton newButton;private JLabel nameLabel;private
8、JLabel prorityLabel;private JLabel timeLabel;private JLabel jobLabel;private JLabel readyLabel;private JLabel waitingLabel;private JLabel runningLabel;private JLabel spaceLabel;private JLabel divLabel;private JLabel allocLabel;private JTable readyTable;private JTable runningTable;private JTable divT
9、able;private JTable allocTable;private JTextField nameText;private JTextField timeText;private JTextField spaceText;private JComboBox prorityCom;private JPanel newPanel;private JPanel waitingPanel;private JPanel readyPanel;Vector jobVectorName;Vector jobDtoVector;Vector waitingVectorName;Vector wait
10、ingDtoVector;PcbDTO readyDtoArray;PcbDTO newDtoArray;divDTO divDtoArray;PcbDTO newSort;Object readydata;Object runningdata;Object divdata;Object allocdata;int first;int end;int point;PcbDTO a ;public MainFrame()a = new PcbDTO();first = 0;end = 0;point = 0;JFrame jf = new JFrame("进程调度-ws");
11、Container c = jf.getContentPane();c.setLayout(null);/c.setBackground(Color.pink);newPanel = new JPanel();newPanel.setLayout(null);waitingPanel = new JPanel();waitingPanel.setLayout(null);/waitingPanel.setBackground(Color.pink);readyPanel = new JPanel();readyPanel.setLayout(null);susButton = new JBut
12、ton("挂起");relaxButton = new JButton("释放");startButton = new JButton("开始");newButton = new JButton("新建进程");nameLabel = new JLabel("进程名");prorityLabel = new JLabel("优先级");timeLabel = new JLabel("运行时间");jobLabel = new JLabel("后备
13、队列");readyLabel = new JLabel("就绪队列");waitingLabel = new JLabel("等待队列");runningLabel = new JLabel("运行进程");spaceLabel = new JLabel("需要空间");divLabel = new JLabel("未分分区表");allocLabel = new JLabel("内存分配表");nameText = new JTextField();timeTe
14、xt = new JTextField();spaceText = new JTextField();prorityCom = new JComboBox();prorityCom.setToolTipText("优先级");readyDtoArray = new PcbDTO6;newSort = new PcbDTO6;for(int i = 0; i< 6;i+)newSorti = new PcbDTO();newDtoArray = new PcbDTO100;jobDtoVector = new Vector();jobVectorName = new V
15、ector();waitingDtoVector = new Vector();waitingVectorName = new Vector();divDtoArray = new divDTO20;for(int i = 0; i < 20; i+)divDtoArrayi = new divDTO();divDtoArrayi.setDivFlag(0);divDtoArray0.setDivFlag(1);divDtoArray0.setDivBase(20);divDtoArray0.setLength(180);readydata = new Object64;runningd
16、ata = new Object23;divdata = new Object203;allocdata = new Object203;String col1 = "进程","时间","优先级","状态"String col2 = "进程","时间","优先级"String col3 = "起址","长度","状态"String col4 = "起址","长度&qu
17、ot;,"占用进程" readyTable = new JTable(readydata,col1);/readyTable.setEnabled(false);runningTable = new JTable(runningdata,col2);runningTable.setRowHeight(22);runningTable.setEnabled(false);allocTable = new JTable(allocdata,col4);allocTable.setEnabled(false);divTable = new JTable(divdata,col3)
18、;divTable.setEnabled(false);divTable.setValueAt(String.valueOf(20),0,0);divTable.setValueAt(String.valueOf(180),0,1);divTable.setValueAt(String.valueOf(1),0,2);JScrollPane runningSP = new JScrollPane();JScrollPane readySP2 = new JScrollPane();JScrollPane divSP = new JScrollPane();JScrollPane allocSP
19、 = new JScrollPane();runningSP.getViewport().add(runningTable);readySP2.getViewport().add(readyTable);divSP.getViewport().add(divTable);allocSP.getViewport().add(allocTable);/int prorityArray = new int10;for(int i = 0;i < 10;i+)prorityCom.addItem(i);/prorityArrayi = i;jobList = new JList();waitin
20、gList = new JList();JScrollPane readySP = new JScrollPane(readyList);JScrollPane jobSP = new JScrollPane(jobList);JScrollPane waitingSP = new JScrollPane(waitingList);newPanel.setSize(450,100);newPanel.setLocation(0,0);nameLabel.setSize(80,20);nameLabel.setLocation(10,5);nameText.setSize(100,25);nam
21、eText.setLocation(10,30);prorityLabel.setSize(80,20);prorityLabel.setLocation(120,5);prorityCom.setSize(100,25);prorityCom.setLocation(120,30);timeLabel.setSize(80,20);timeLabel.setLocation(230,5);timeText.setSize(100,25);timeText.setLocation(230,30);spaceLabel.setSize(80,20);spaceLabel.setLocation(
22、340,5);spaceText.setSize(100,25);spaceText.setLocation(340,30);newButton.setSize(100,20);newButton.setLocation(320,70);waitingPanel.setSize(190,410);waitingPanel.setLocation(0,100);jobLabel.setSize(100,20);jobLabel.setLocation(10,2);jobSP.setSize(180,105);jobSP.setLocation(10,25);waitingLabel.setSiz
23、e(100,20);waitingLabel.setLocation(10,129);waitingSP.setSize(180,105);waitingSP.setLocation(10,150);divLabel.setSize(100,20);divLabel.setLocation(10,253);divSP.setSize(180,113);divSP.setLocation(10,273);relaxButton.setSize(80,20);relaxButton.setLocation(110,388);readyPanel.setSize(260,410);readyPane
24、l.setLocation(190,100);readyLabel.setSize(100,22);readyLabel.setLocation(10,2);allocLabel.setSize(100,20);allocLabel.setLocation(10,232);startButton.setSize(80,20);startButton.setLocation(177,388);susButton.setSize(80,20);susButton.setLocation(95,388);readySP2.setSize(250,117);readySP2.setLocation(1
25、0,25);runningLabel.setLocation(10,142);runningLabel.setSize(100,20);runningSP.setSize(250,65);runningSP.setLocation(10,167);allocSP.setSize(250,130);allocSP.setLocation(10,255);c.add(newPanel);newPanel.add(nameLabel);newPanel.add(nameText);newPanel.add(prorityLabel);newPanel.add(prorityCom);newPanel
26、.add(timeText);newPanel.add(timeLabel);newPanel.add(newButton);newPanel.add(spaceLabel);newPanel.add(spaceText);c.add(waitingPanel);waitingPanel.add(jobLabel);waitingPanel.add(jobSP);waitingPanel.add(waitingLabel);waitingPanel.add(waitingSP);waitingPanel.add(divLabel);waitingPanel.add(divSP);waiting
27、Panel.add(relaxButton);c.add(readyPanel);readyPanel.add(readyLabel);readyPanel.add(allocLabel);readyPanel.add(runningLabel);readyPanel.add(startButton);readyPanel.add(susButton);readyPanel.add(allocSP);readyPanel.add(runningSP);readyPanel.add(readySP2);jf.setSize(470,550);jf.setDefaultCloseOperation
28、(JFrame.DISPOSE_ON_CLOSE); jf.setLocationRelativeTo(null); jf.setVisible(true); startButton.addActionListener(new MyActionListener();newButton.addActionListener(new MyActionListener();susButton.addActionListener(new MyActionListener();relaxButton.addActionListener(new MyActionListener();public void
29、sus()tryThread.sleep(1000);catch(Exception ex)class MyActionListener implements ActionListener public void actionPerformed(ActionEvent e)int count = 0;PcbDTO test = new PcbDTO();JButton jb = (JButton)e.getSource();int max = -1;if(jb = startButton)/while(true)/int runAllocFlag = -1;if(String)runningT
30、able.getValueAt(0,0)=null|(String)runningTable.getValueAt(0,0)="")tryThread.sleep(0);catch(Exception ex)/System.out.println("到3");for(int j = first;j != end; )if(!readyDtoArrayj.getProcessState().equals("waiting")max = j;break;j = (j+1)%6;for(int j = first;j%6 != end; )
31、if(!readyDtoArrayj.getProcessState().equals("waiting")if(readyDtoArrayj.getPrority() > readyDtoArraymax.getPrority()max = j;j = (j+1)%6;if(max>=0)a = readyDtoArraymax;readyDtoArraymax = readyDtoArrayfirst;readyDtoArrayfirst = a;readyTable.setValueAt(readyDtoArraymax.getProcessName(),
32、max,0);readyTable.setValueAt(readyDtoArraymax.getRunTime(),max,1);readyTable.setValueAt(readyDtoArraymax.getPrority(),max,2);readyTable.setValueAt(readyDtoArraymax.getProcessState(),max,3);readyTable.setValueAt("",first,0);readyTable.setValueAt("",first,1);readyTable.setValueAt(&
33、quot;",first,2);readyTable.setValueAt("",first,3);runningTable.setValueAt(a.getProcessName(),0,0);runningTable.setValueAt(a.getRunTime(),0,1);runningTable.setValueAt(a.getPrority(),0,2);readyDtoArrayfirst.setRunTime(readyDtoArrayfirst.getRunTime()-1);if(0 != readyDtoArrayfirst.getPror
34、ity()readyDtoArrayfirst.setPrority(readyDtoArrayfirst.getPrority()-1);first = (first+1)%6;elseSystem.out.println("cpu等待中");else /*tryThread.sleep(2000);catch(InterruptedException e1)System.out.println(e1);*/System.out.println("到1");runningTable.setValueAt("",0,0);runnin
35、gTable.setValueAt("",0,1);runningTable.setValueAt("",0,2);/如果运行时间为0则撤销进程,否则将进程重新添加到就绪队列中if( a.getRunTime()<=0)/收回内存空间for(int i = 0;i < point; i+)if(newSorti.getBase()>=a.getBase()newSorti = newSorti+1;point-;/设置内存分配表的内容for(int i = 0; i < point;i+)allocTable.setValueAt
36、(String.valueOf(newSorti.getBase(),i,0);allocTable.setValueAt(String.valueOf(newSorti.getLimit(),i,1);allocTable.setValueAt(newSorti.getProcessName(),i,2); allocTable.setValueAt("",point,0);allocTable.setValueAt("",point,1);allocTable.setValueAt("",point,2);/把收回的内存加入到记录
37、未分分区的数组int memoryEnd = 0;int location = 0;int up = -1;/int down = -1;for(int i = 0;i<20;i+)if(divDtoArrayi.getDivFalg() = 1)memoryEnd = divDtoArrayi.getDivBase()+divDtoArrayi.getLength();if(memoryEnd = a.getBase()up = i;if(divDtoArrayi.getDivBase() = (a.getBase()+a.getLimit()down = i;if(up >=
38、0&&down >= 0)divDtoArrayup.setLength(divDtoArrayup.getLength()+a.getLimit()+divDtoArraydown.getLength();divDtoArraydown.setDivFlag(0);for(int i = (down+1); i < 20;i+)if(divDtoArrayi.getDivFalg() = 1)divDtoArrayi-1.setDivBase(divDtoArrayi.getDivBase(); divDtoArrayi-1.setDivFlag(1); divD
39、toArrayi-1.setLength(divDtoArrayi.getLength();divDtoArrayi.setDivFlag(0);elsedivTable.setValueAt("",i-1,0);divTable.setValueAt("",i-1,1);divTable.setValueAt("",i-1,2);break;else if(up >= 0&&down < 0)divDtoArrayup.setLength(divDtoArrayup.getLength()+a.getLi
40、mit();else if(up < 0&&down >= 0)divDtoArraydown.setLength(divDtoArraydown.getLength()+a.getLimit();divDtoArraydown.setDivBase(a.getBase();else if(up < 0&&down < 0)for(int i = 0; i < 20; i+)if(divDtoArrayi.getDivBase()>a.getBase()|divDtoArrayi.getDivFalg()=0)location
41、 = i;break; for(int i = 20; i >location;i-) if(divDtoArrayi-1.getDivFalg()=1) divDtoArrayi.setDivBase(divDtoArrayi-1.getDivBase(); divDtoArrayi.setDivFlag(1); divDtoArrayi.setLength(divDtoArrayi-1.getLength(); divDtoArraylocation.setDivBase(a.getBase(); divDtoArraylocation.setDivFlag(1); divDtoAr
42、raylocation.setLength(a.getLimit();/设置未分分区表的内容for(int i = 0; i < 20;i+) if(divDtoArrayi.getDivFalg()=1) divTable.setValueAt(String.valueOf(divDtoArrayi.getDivBase(),i,0);divTable.setValueAt(String.valueOf(divDtoArrayi.getLength(),i,1);divTable.setValueAt(String.valueOf(divDtoArrayi.getDivFalg(),i
43、,2); if(!jobDtoVector.isEmpty() int runLength = 0;PcbDTO jobToReady = (PcbDTO)jobDtoVector.elementAt(0);for(int i = 0; i < 20; i+)if(divDtoArrayi.getDivFalg() = 1)if(divDtoArrayi.getLength() >= jobToReady.getLimit()runAllocFlag = i;break;if(runAllocFlag >= 0)jobDtoVector.removeElementAt(0);
44、jobVectorName.remove(jobVectorName.indexOf(jobToReady.getProcessName();jobList.setListData(jobVectorName);jobToReady.setProcessState(PcbDTO.Ready);jobToReady.setBase(divDtoArrayrunAllocFlag.getDivBase();runLength = divDtoArrayrunAllocFlag.getLength()- jobToReady.getLimit();if(runLength = 0)int i = r
45、unAllocFlag;divDtoArrayi.setDivFlag(0);for(; i < 19;i+)if(divDtoArrayi+1.getDivFalg() = 1)divDtoArrayi = divDtoArrayi+1;divDtoArrayi+1.setDivFlag(0);divTable.setValueAt(String.valueOf(divDtoArrayi.getDivBase(),i,0);divTable.setValueAt(String.valueOf(divDtoArrayi.getLength(),i,1);divTable.setValue
46、At(String.valueOf(divDtoArrayi.getDivFalg(),i,2);divTable.setValueAt(String.valueOf(divDtoArrayi.getDivFalg(),i,2);else if(runLength > 0)int c2 = divDtoArrayrunAllocFlag.getDivBase()+ jobToReady.getLimit();divDtoArrayrunAllocFlag.setDivBase(c2);divDtoArrayrunAllocFlag.setLength(runLength);divTable.setValueAt(String.valueOf(c2),runAllocFlag,0);divTable.setValueAt(String.valueOf(runLength),runAllocFlag,1);divTable.setValueAt(String.valueOf(divDtoArrayrunAllocFlag.getDivFalg(),
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 《金融服务营销》 测试题及答案A
- 工业废水处理与排放标准环境监测研究
- 工业机器人应用及操作规范介绍
- 工业旅游开发与文化传承研究
- 工业机器人技术及智能制造应用案例
- 工作与生活平衡-如何在智能环境内获得幸福感
- 23类安全管理制度
- 4s店部门管理制度
- 柴油存放管理管理制度
- 标识标牌仓库管理制度
- 项目工程实体质量(路基、路面工程)检查表
- 图文高中英语语法if条件句If - Clauses
- 中国网民权益保护调查报告
- 2022年四川省成考(专升本)经济学考试真题含解析
- 大模型在航空航天领域的应用:智能探索宇宙的无限可能
- 《直流电源》课件
- 《中医药健康知识讲座》课件
- 解决多模穴流动不平衡问题之流道翻转技术
- 民俗文化的产业化发展
- 抖音新号怎么养号
- 国开02316-中级财务会计(一)机考复习资料
评论
0/150
提交评论