package swing;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import model.Pcb;
import model.PcbFactory;
import algorithm.Algorithm;
import algorithm.Fcfs;
import algorithm.Rr;
import algorithm.Sjf;
import algorithm.Tss;
public class MyFrame extends JFrame{
public MyFrame()
{
setTitle("完美的单处理机进程调度模拟程序");
setIconImage(img);
MyPanel panel=new MyPanel();
add(panel);
setVisible(true);
setResizable(false);
this.setLocation(300, 200);
this.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
}
private final int DEFAULT_WIDTH =490;
private final int DEFAULT_HEIGHT=310;
private static Toolkit kit = Toolkit.getDefaultToolkit();
private static Image img = kit.getImage("002.png");
private ImageIcon background;
}
class MyPanel extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2=(Graphics2D) g;
ImageIcon icon = new ImageIcon("24.jpg");
Image img = icon.getImage();
g.drawImage(img, 0, 0, icon.getIconWidth(), icon.getIconHeight(), icon.getImageObserver());
}
public MyPanel()
{
panelA=new JPanel();
panelB=new JPanel();
panelC=new JPanel();
panelD=new JPanel();
panelE=new JPanel();
panelA.setOpaque(false);
panelB.setOpaque(false);
panelC.setOpaque(false);
panelD.setOpaque(false);
panelE.setOpaque(false);
label1=new JLabel("随机产生的进程个数:");
label1.setFont(new Font("Serif",Font.PLAIN,FONTSIZE1));
pcbnu=new JComboBox();
pcbnu.setEditable(true);
for(int i=1;i<=10;i++)
{
pcbnu.addItem(i);
}
pcbnu.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e) {
number=(Integer) pcbnu.getSelectedItem();
}
});
panelA.add(label1);
panelA.add(pcbnu);
label2=new JLabel("请选择进程调度算法:");
label2.setFont(new Font("Serif",Font.PLAIN,FONTSIZE2));
panelB.setLayout(new GridLayout(2,1));
panelE.setLayout(new GridLayout(2,2));
group=new ButtonGroup();
addRadioButton("先来先服务","fcfs");
addRadioButton("高响应比优先调度算法","rr");
addRadioButton("段进程优先算法","sjf");
addRadioButton("时间片轮转算法","tss");
panelD.add(label2);
panelB.add(panelD);
panelB.add(panelE);
okButton=new JButton("OK");
pauseButton=new JButton("PAUSE");
stopButton=new JButton("STOP");
okButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e) {
if(!check())
return;
timeChip=-1;
tf=new TableFrame(alg);
tf.setTitle("进程调度时间表");
tf.setVisible(true);
tf.setSize(350,200);
tf.setLocation(800,20);
ef=new EventFrame(alg);
ef.setTitle("进程调度事件表");
ef.setVisible(true);
ef.setSize(350,200);
ef.setLocation(800,350);
}
});
pauseButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e) {
}
});
stopButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e) {
}
});
panelC.add(okButton);
panelC.add(pauseButton);
panelC.add(stopButton);
JPanel panelF=new JPanel();
panelF.setOpaque(false);
JLabel l1=new JLabel("版权所有:高关岭同学 本软件纯属虚构,如有雷同,你抄我的。");
l1.setOpaque(false);
JLabel l2=new JLabel("版权所有,翻录者,斩立决!!");
l2.setOpaque(false);
panelF.setLayout(new FlowLayout());
panelF.add(l1);
panelF.add(l2);
this.setLayout(new GridLayout(4,1));
add(panelA);
add(panelB);
add(panelC);
add(panelF);
}
//--事件监听器
public void addRadioButton(String te, String flag)
{
final String temp=flag;
JRadioButton radio=new JRadioButton(te);
radio.setOpaque(false);
radio.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e) {
algorithm=temp;
}
});
group.add(radio);
panelE.add(radio);
}
public boolean check()
{
if(number==0)
{
setDialog("对不起,进程数量不可以为"+number);
return false;
}
if(algorithm==null)
{
setDialog("对不起,必须选定算法");
return false;
}
pcf=new PcbFactory(number);
pcbList= pcf.getPcbs();
System.out.println("已经生成的PCB列表: "+pcbList.toString());
if(algorithm=="fcfs")
{
alg=new Fcfs(pcbList);
System.out.println("按fcfs算法生成的PCB列表: "+alg.getPcbList().toString());
}
else if(algorithm=="sjf")
{
alg=new Sjf(pcbList);
System.out.println("按sjf算法生成的PCB列表: "+alg.getPcbList().toString());
}
else if(algorithm=="rr")
{
alg=new Rr(pcbList);
System.out.println("按Rr算法生成的PCB列表: "+alg.getPcbList().toString());
}
else if(algorithm=="tss")
{
if(timeChip<=0)
{
setMessage("请输入时间片的大小:");
return false;
}
alg=new Tss(pcbList,timeChip);
System.out.println("按Tss算法生成的PCB列表: "+alg.getPcbList().toString());
}
return true;
}
public void setDialog(String words)
{
this.jlg=new JDialog();
JLabel la=new JLabel(words);
jlg.add(la);
jlg.pack();
jlg.setLocationRelativeTo(this);
jlg.setVisible(true);
}
public void setMessage(String words)
{
this.jlg=new JDialog();
JLabel la=new JLabel(words);
JButton bu=new JButton("OK");
this.text=new JTextField();
bu.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e) {
timeChip=Integer.valueOf(text.getText());
jlg.setVisible(false);
}
});
jlg.add(la,BorderLayout.NORTH);
jlg.add(text,BorderLayout.CENTER);
jlg.add(bu,BorderLayout.SOUTH);
jlg.setSize(200,120);
jlg.setLocationRelativeTo(this);
jlg.setVisible(true);
}
private JPanel panelA;
private JPanel panelB;
private JPanel panelC;
private JPanel panelD;
private JPanel panelE;
private JLabel label1;
private JLabel label2;
private ButtonGroup group;
private JRadioButton fcfs;
private JRadioButton mfqs;
private JRadioButton rr;
private JRadioButton sjf;
private JRadioButton tss;
private JComboBox pcbnu;
private JButton okButton;
private JButton pauseButton;
private JButton stopButton;
private JDialog jlg;
private static final int FONTSIZE1=20;
private static final int FONTSIZE2=18;
private int number=1;
private String algorithm=null;
private Algorithm alg;
private ArrayList<Pcb> pcbList;
PcbFactory pcf;
private TableFrame tf;
private EventFrame ef;
private int timeChip=-1;
private JTextField text;
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
OS.rar (42个子文件)
OS
.project 378B
src
model
MyEvent.java 480B
PcbFactory.java 860B
Pcb.java 2KB
swing
MyFrame.java 7KB
TableFrame.java 2KB
EventFrame.java 2KB
test
Test.java 354B
algorithm
Algorithm.java 211B
Rr.java 4KB
Fcfs.java 3KB
Tss.java 3KB
Sjf.java 4KB
.settings
org.eclipse.jdt.core.prefs 629B
17.jpg 29KB
42.jpg 22KB
002.png 5KB
24.jpg 40KB
.classpath 301B
23.jpg 41KB
bin
model
MyEvent.class 1007B
Pcb.class 2KB
PcbFactory.class 1KB
swing
MyPanel$5.class 779B
MyPanel$6.class 1KB
MyPanel$3.class 606B
TableFrame.class 3KB
TableFrame$1.class 955B
EventFrame.class 2KB
MyPanel$4.class 606B
EventFrame$1.class 955B
MyPanel$1.class 868B
MyPanel.class 8KB
MyFrame.class 1KB
MyPanel$2.class 1KB
test
Test$1.class 580B
Test.class 507B
algorithm
Rr.class 4KB
Fcfs.class 3KB
Sjf.class 3KB
Algorithm.class 286B
Tss.class 3KB
共 42 条
- 1
资源评论
- zhouyi19962014-02-07不对啊,这根本不是操作系统。。。。
- qinqinqwodetao2013-10-20不错。挺好的。。。
- tassy5202015-06-11不错~可以运行!
- qq_255773472015-10-17不错,可以参考
- --星河战神--2014-09-05不错,是进程调度算法的模拟,还可以选择调度方式!
msj100ff
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功