package cn.qujialin.myframe;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import cn.qujialin.myprocess.FCFS;
import cn.qujialin.myprocess.HPF;
import cn.qujialin.myprocess.MyProcess;
import cn.qujialin.myprocess.MyQueue;
import cn.qujialin.myprocess.SF;
public class MainFrame extends JFrame{
/**
* 主窗口
*/
private static final long serialVersionUID = 1L;
private static int dp_method=0;
public MainFrame()
{
setTitle("进程管理系统模拟");
setLayout(null);
setBounds(200,70,1180,700);
Font font = new Font("宋体", Font.BOLD, 16);
setResizable(false);// 设置窗体不能改变尺寸
Container co=getContentPane();
co.setLayout(null);
JPanel panel1=new JPanel();
JPanel panel2=new JPanel();
JPanel panel3=new JPanel();
JPanel panel4=new JPanel();
JPanel panel5=new JPanel();
JPanel panel6=new JPanel();
panel1.setBounds(10, 10, 350, 635);
panel1.setLayout(null);
panel1.setBackground(Color.gray);
panel2.setBackground(Color.gray);
panel3.setBackground(Color.gray);
panel4.setBackground(Color.gray);
panel5.setBackground(Color.gray);
panel6.setBackground(Color.gray);
panel2.setBounds(370, 10, 780, 635);
panel2.setLayout(null);
panel3.setBounds(10, 320, 760, 310);
panel3.setLayout(null);
panel4.setBounds(10, 5, 760, 310);
panel4.setLayout(null);
panel5.setBounds(25, 285, 300, 180);
panel5.setLayout(null);
panel6.setBounds(25, 480, 300, 140);
panel6.setLayout(null);
//设计Panel1
Vector<String> colName=new Vector<>();
colName.add("进程名");
colName.add("到达时间");
colName.add("运行时间");
colName.add("优先级");
colName.add("状态");
Vector<Vector<String>> tableValue=new Vector<>();
JTable p1_jt1=new JTable();
//设计Panel4
JTextArea p4_info=new JTextArea(10,50);
p4_info.setBounds(10,20,740,280);
p4_info.setFont(new Font("宋体", Font.BOLD, 13));
p4_info.setEditable(false);
JScrollPane p4_jscroll = new JScrollPane();// 将文本域放入滚动面板中
p4_jscroll.setViewportView(p4_info);
p4_jscroll.setBounds(10,20,740,280);
panel4.add(p4_jscroll);
//设计Panel3
JTextArea p3_info=new JTextArea(10,50);
p3_info.setBounds(10,20,740,280);
p3_info.setFont(new Font("宋体", Font.BOLD, 13));
p3_info.setEditable(false);
JScrollPane p3_jscroll = new JScrollPane();// 将文本域放入滚动面板中
p3_jscroll.setViewportView(p3_info);
p3_jscroll.setBounds(10,20,740,280);
panel3.add(p3_jscroll);
//设计Panel1
JLabel p1_namel=new JLabel("进程名:");
JLabel p1_arrivetimel=new JLabel("到达时间:");
JLabel p1_runtimel=new JLabel("运行时间:");
JLabel p1_priorityl=new JLabel("优先级:");
JLabel p1_statusl=new JLabel("状态:");
JTextField p1_name=new JTextField();
JTextField p1_arrivetime=new JTextField();
JTextField p1_runtime=new JTextField();
JTextField p1_priority=new JTextField();
JTextField p1_status=new JTextField();
JButton p1_submit=new JButton("确定");
JButton p1_clear=new JButton("清空");
JButton p5_clear=new JButton("清空进程信息");
JButton p5_block=new JButton("阻塞");
JButton p5_wakeup=new JButton("唤醒");
JButton p5_start=new JButton("开始");
JButton p5_remove=new JButton("撤销当前进程");
JComboBox<String> p5_box=new JComboBox<>();
p5_box.addItem("--请选择调度算法--");
p5_box.addItem("01-FCFS");
p5_box.addItem("02-SF");
p5_box.addItem("03-HPF");
p5_box.setFont(font);
p5_box.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
// TODO Auto-generated method stub
if(((String)p5_box.getSelectedItem()).equals("--请选择调度算法--"))
{
JOptionPane.showMessageDialog(null, "请选择调度算法!", "调度算法", JOptionPane.INFORMATION_MESSAGE);
}else {
dp_method=Integer.parseInt(((String)p5_box.getSelectedItem()).substring(1, 2));
}
}
});
panel5.add(p5_box);
//撤销
p5_remove.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
MyProcess osp=new MyProcess(p1_name.getText()
,Integer.parseInt(p1_arrivetime.getText())
,Integer.parseInt(p1_runtime.getText())
,Integer.parseInt(p1_priority.getText())
,p1_status.getText());
int index=MyQueue.ready.indexOf(osp);
if(index!=-1)
{
osp.setStatus("remove");
MyQueue.ready.get(index).setStatus("remove");
//从ready队列删除进程
MyQueue.process.clear();
for (int i = 0; i < MyQueue.ready.size(); i++) {
MyQueue.process.add(MyQueue.ready.get(i));
}
MyQueue.ready.clear();
for (int i = 0; i < MyQueue.process.size(); i++) {
if(!MyQueue.process.get(i).equals(osp))
{
MyQueue.ready.add(MyQueue.process.get(i));
}
}
MyQueue.process.clear();
JOptionPane.showMessageDialog(null, "撤销成功", "撤销成功", JOptionPane.INFORMATION_MESSAGE);
}else
{
index=MyQueue.block.indexOf(osp);
if(index!=-1)
{
osp.setStatus("remove");
MyQueue.block.get(index).setStatus("remove");
//从阻塞队列删除进程
MyQueue.process.clear();
for (int i = 0; i < MyQueue.block.size(); i++) {
MyQueue.process.add(MyQueue.block.get(i));
}
MyQueue.block.clear();
for (int i = 0; i < MyQueue.process.size(); i++) {
if(!MyQueue.process.get(i).equals(osp))
{
MyQueue.block.add(MyQueue.process.get(i));
}
}
MyQueue.process.clear();
JOptionPane.showMessageDialog(null, "撤销成功", "撤销成功", JOptionPane.INFORMATION_MESSAGE);
}else {
JOptionPane.showMessageDialog(null, "运行/阻塞队列均没有当前进程", "撤销失败", JOptionPane.ERROR_MESSAGE);
}
}
}
});
//唤醒
p5_wakeup.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
MyProcess osp=new MyProcess(p1_name.getText()
,Integer.parseInt(p1_arrivetime.getText())
,Integer.parseInt(p1_runtime.getText())
,Integer.parseInt(p1_priority.getText())
,p1_status.getText());
//osp.setArrivetime(osp.getArrivetime()+99999999);
int index=MyQueue.block.indexOf(osp);
if(index!=-1)
{
osp.setStatus("wait");
// osp.setArrivetime(osp.getArrivetime()-99999999);
MyQueue.block.get(index).setStatus("wait");
MyQueue.block.get(index).setFlag(true);
// MyQueue.block.get(index).setArrivetime(MyQueue.block.get(index).getArrivetime()-99999999);
MyQueue.ready.add(MyQueue.block.get(index));//添加到运行队列
FCFS.sort();
//从阻塞队列删除进程
MyQueue.process.clear();
for (int i = 0; i < MyQueue.block.size(); i++) {
MyQueue.process.add(MyQueue.block.get(i));
}
MyQueue.block.clear();
for (int i = 0; i < MyQueue.process.size(); i++) {
if(!MyQueue.process.get(i).equals(osp))
{
MyQueue.block.add(MyQueue.process.get(i));
}
}
MyQueue.process.clear();
JOptionPane.showMessageDialog(null, "唤醒成功", "唤醒成功", JOptionPane.INFORMATION_MESSAGE);
}else
{
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Java操作系统课设之模拟进程管理系统.zip (32个子文件)
OsWork
bin
cn
qujialin
myprocess
FCFS.class 5KB
SF.class 5KB
HPF.class 5KB
MyQueue.class 822B
MyProcess.class 3KB
myframe
MainFrame.class 7KB
MainFrame$7.class 2KB
MainFrame$5.class 1KB
MainFrame$4.class 3KB
Panel1.class 289B
Panel2.class 285B
Panel3.class 285B
MainFrame$3.class 2KB
MainFrame$6.class 933B
MainFrame$5$2.class 826B
MainFrame$5$1.class 828B
MainFrame$2.class 3KB
MainFrame$1.class 1KB
MainFrame$5$3.class 827B
MainFrame$8.class 1KB
.settings
org.eclipse.jdt.core.prefs 405B
src
cn
qujialin
myprocess
MyProcess.java 2KB
FCFS.java 5KB
SF.java 5KB
HPF.java 5KB
MyQueue.java 567B
myframe
Panel2.java 104B
Panel3.java 104B
MainFrame.java 16KB
Panel1.java 130B
.project 382B
.classpath 328B
共 32 条
- 1
资源评论
- _不执_2019-06-22非常好,帮了大忙
- 格里芬阀门工2019-06-17能跑,有点小BUG,比如运行途中加入进程时可能会导致已经结束的进程再次执行。不过问题不大,而且界面好看,满分
- TinaGioro2019-07-26运行不起来,全是错
凡人X
- 粉丝: 191
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功