操作系统进程调度仿真程序源码

2019-08-31 15:10

import java.util.*;

public class PCB{

int priority; //优先级

Date createTime,startTime,finishTime; //提交时间,开始时间,完成时间 String create,start,finish;

int id,runTime,counter=0; //进程ID,运行耗时,运行计时 long l1,l2;

double perTime; public PCB(){

Date createTime=new Date(); l2=createTime.getTime();

create=String.format(\ priority=(int)(Math.random()*10+1); runTime=(int)(Math.random()*56+5); }

public PCB(int runTime,int priority){ Date createTime=new Date(); l2=createTime.getTime();

create=String.format(\ this.priority=priority;

this.runTime=runTime; }

public void inputID(int id){ this.id=id;

}

public void inputStartTime(Date startTime){ this.startTime=startTime;

start=String.format(\ }

public void inputFinishTime(Date finishTime){ this.finishTime=finishTime;

l1=finishTime.getTime();

finish=String.format(\ }

public void inputCounter(int counter){ this.counter=counter; }

public int getID(){ return id;

}

public int getPriority(){ return priority; }

public String getCreateTime(){ return create; }

public int getRunTime(){ return runTime; }

public String getStartTime(){ return start;

}

public String getFinishTime(){ return finish; }

public double getPerTime(){

perTime=(l1-l2)/(runTime*1000.0); return perTime; }

public int getCounter(){ return counter; }

public Date getFromTime(){ return createTime; } }

//------------------------------------------------------------------------------------------------------

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

import java.awt.event.*; import javax.swing.table.*; import java.util.*; import java.io.*;

public class MainClass implements ActionListener{

int pri=5; //存放所选择的优先级 String item; //存放所选择的模式

Vector nm1,nm2,nm3,nm4; //各个表头信息 Vector allData=new Vector(); //存放生成的所有对象 Vector runData=new Vector(); //运行进程显示数据

Vector readyData=new Vector(); //就绪队列显示数据

Vector waitData=new Vector(); //阻塞队列显示数据 Vector finishData=new Vector(); //完成队列显示数据 Vector FCFS=new Vector(); //先来先服务 Vector PF=new Vector(); //静态优先级调度

Vector DPF=new Vector(); //动态优先级调度 Vector SJF=new Vector(); //最短作业优先 Vector SRTF=new Vector(); //最短剩余时间优先 static int id=0;

int times=0; //打印运行结果次数

boolean active=true,stop; //运行与暂停标志,阻塞与否标志 JFrame frame;

JLabel jl1,jl2,jl3,jl4,jl5,jl6,jl7,jl8; JScrollPane jsp0,jsp1,jsp2,jsp3; JTextField now,tm;

JComboBox mode,priorityBox;

JButton createprocess,interrupt,controll,wakeup,save,exit; MTable runprocess,ready,interrupted,finish;

public MainClass(){

frame=new JFrame(\进程调度仿真——3118310_池毓兴&&1928105_王慧娟\ frame.setSize(800,650);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container c=frame.getContentPane(); c.setLayout(null); c.setBounds(0,0,800,600);

jl1=new JLabel(\当前时间:\ jl1.setForeground(Color.red); jl1.setBounds(10,10,70,20); c.add(jl1);

now=new JTextField(5);

Thread thread0=new Thread(new Runnable(){ public void run(){ try{

while(true)

{

Date time=new Date();

String nowtime=String.format(\ now.setText(nowtime); Thread.sleep(1000); }

}catch(InterruptedException e) {

e.printStackTrace(); } } });

thread0.start(); now.setEditable(false);

now.setBackground(Color.black); now.setForeground(Color.green); now.setBounds(80,10,60,20); c.add(now);

jl2=new JLabel(\调度模式:\ jl2.setForeground(Color.red);

c.add(jl2);

jl2.setBounds(280,10,70,20);

String items[]={\先来先服务算法\静态优先级调度算法\动态优先级调度算法\最短作业优先算法\最短剩余时间优先算法\ mode=new JComboBox(items); mode.setSelectedIndex(0);

mode.addItemListener(new ModeChoice());

mode.setEditable(false); mode.setSize(2,18);

c.add(mode); //调度模式设置 mode.setBounds(350,10,150,20);

jl4=new JLabel(\优先级选择:\ jl4.setForeground(Color.red); jl4.setBounds(10,35,90,20); c.add(jl4);

Object itm[]={1,2,3,4,5,6,7,8,9,10}; priorityBox=new JComboBox(itm);

priorityBox.setSelectedIndex(4);

priorityBox.addItemListener(new ItemListener(){ public void itemStateChanged(ItemEvent e){ String stri=e.getItem().toString(); pri=Integer.parseInt(stri); } });

priorityBox.setEditable(false);

priorityBox.setBounds(100,35,50,20);

c.add(priorityBox); //优先级输入

jl3=new JLabel(\运行耗时:\

jl3.setForeground(Color.red);

jl3.setBounds(280,35,70,20); c.add(jl3);

tm=new JTextField(5);

tm.setBounds(350,35,150,20);

c.add(tm); //运行耗时输入

createprocess=new JButton(\创建进程\ createprocess.setBounds(650,35,100,25);

c.add(createprocess);

createprocess.addActionListener(this); //监听器

controll=new JButton(); //进程控制 if(active)

controll.setText(\暂停运行\ else

controll.setText(\开始运行\

controll.setBounds(650,5,100,25); c.add(controll);

controll.addActionListener(this); //监听器

jl8=new JLabel(\当前进程:\

jl8.setForeground(Color.red); jl8.setBounds(10,60,150,20); c.add(jl8);

//-----------------------------运行进程JTable

String[] name1={\进程ID\优先级\提交时间\运行耗时\开始时间\运行计时\

nm1=new Vector();

for(int column=0;column

runprocess=new MTable(runData,nm1);

// runprocess.setPreferredScrollableViewportSize(new Dimension(500,50)); // runprocess.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

runprocess.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); runprocess.setSelectionBackground(Color.yellow); runprocess.setSelectionForeground(Color.red); // runprocess.setRowHeight(30); jsp0=new JScrollPane();

jsp0.setViewportView(runprocess); jsp0.setBounds(10,85,600,37); c.add(jsp0); interrupt=new JButton(\

阻塞进程\


操作系统进程调度仿真程序源码.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

Copyright © 2019-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18

× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: