{
ProcessPCB stu_Item = (ProcessPCB)iterator1.next(); itemsProperties[i++] = stu_Item.toString(); }
return itemsProperties; }
public Iterator
MemoryRecords.java package src;
import java.util.ArrayList; import java.util.Iterator;
public class MemoryRecords implements Iterable
public Iterator
public ArrayList
public MemoryRecords() {
this.memoryItems = new ArrayList
public void addItem(MemoryItem newMemoryItem) { this.memoryItems.add(newMemoryItem); }
public void removeItem(MemoryItem momoryItem) { this.memoryItems.remove(momoryItem); }
public MemoryItem getMomoryItem(MemoryItem item) { for(MemoryItem mItem : this.memoryItems) { if(mItem.equals(item)) { return mItem; } }
return null; }
public MemoryItem getMemoryItem(int base) { for(MemoryItem mItem : this.memoryItems) { if(mItem.getMemoryBase() == base) { return mItem; } }
return null;
}
public int getNumberOfItems() { return this.memoryItems.size(); }
public String[] getItemsProperties() {
String itemsProperties[] = new String[getNumberOfItems()]; int i=0;
for(Iterator iterator1 = this.memoryItems.iterator(); iterator1.hasNext(); ) { MemoryItem mmItem = (MemoryItem) iterator1.next(); itemsProperties[i++] = mmItem.toString();//???? }
//System.out.println(itemsProperties + \ if(itemsProperties == null) { itemsProperties[0] = \ \ }
return itemsProperties; } }
SingleCPUSchedulingGUI001.Java
import java.util.*; import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import src.SingleCPUSchedulingGUI001.AddToBAKListener; import src.SingleCPUSchedulingGUI001.AddToReadyListener; import src.SingleCPUSchedulingGUI001.RemoveListener; import src.SingleCPUSchedulingGUI001.ResetListener;
import src.SingleCPUSchedulingGUI001.ResetSystemListener; import src.SingleCPUSchedulingGUI001.StartSystemListener; import src.SingleCPUSchedulingGUI001.SuspendListener; import src.SingleCPUSchedulingGUI001.SystemPauseListener; import src.SingleCPUSchedulingGUI001.UmountListener; import src.SingleCPUSchedulingGUI001.priotiryListener; import src.SingleCPUSchedulingGUI001.timeslicListener;
import java.io.*; import java.text.*;
public class SingleCPUSchedulingGUI001 extends JFrame {
private int systemStatues; //注意static 属性
/*define 0--system prepare status--system reset and re-prepare 1--system start 2--system pause 3--system stop*/
/* Standar error stream */
static private PrintWriter stdErr = new PrintWriter(System.err, true);
static private int WIDTH = 600, HEIGHT = 700; // the size of the Frame 主面板
/* 各列表对应的面板规格*/
/* 对应各名词释义 backupBAK 后备 ready 就绪 suspend 挂起 memory内存 */ static private int BackupBAK_CELL_SIZE = 250, BackupBAK_LIST_ROWS = 10; //后备队列 static private int Suspend_CELL_SIZE = 250, Suspend_LIST_ROWS = 10; //挂起队列
static private int Ready_CELL_SIZE = 200, Ready_LIST_ROWS = 6; //就绪队列 static private int CPU_ROWS = 10, CPU_COLS = 22; //CPU面板 static private int STATUS_ROWS = 8, STATUS_COLS = 30; //系统状态面板 private int timeslice = 1; //设置时间片大小
private int systemStatus=0; //设置系统状态 0——系统预备状态,等待开始,1——系统运行状态,2——系统暂停状态
static private int TOTAL__TEXTFIELD_SIZE = 10; // Size total text field 记录各队列元素个数
private JList backupList, suspendList, readyList; //各队列相对应的数组列表 // 进程添加框中的\添加至后备队列\,\添加至就绪队列\,\重置\ private JButton addToBAKButton, addToReadyButton, resetButton; //就绪队列框中的\挂起\,挂起队列框中的\解挂\,\删除\ private JButton suspendButton, umountButton, removeButton; //Status面板中的\启动系统\,\重置系统\
private JButton startButton, pauseButton, resetSyatemButton; //优先级和时间片单选钮及时间片显示框 private JRadioButton priorityJRB, timesliceJRB; private JLabel timesliceSizeLabel; private JTextField timesliceJtf;
//后备面板、进程添加面板、挂起面板、内存面板
private JPanel backupBAKPanel, PCBItemPanel, suspendedPanel; //后备队列、挂起队列元素总数标签 private JLabel backupTotalLabel, suspendTotalLabel;
//进程信息标签 进程编号PID,所需运行时间requiredTime,优先级priority,当前状态statues,内存中的基址base,所需内存大小limit
private JLabel PIDLabel, requiredTimeLabel, priorityLabel, statuesLabel; //后备队列、挂起队列元素总数文本框(不可编辑) private JTextField backupTotalTextField, suspendTotalTextField;
//进程信息文本框 PID(可编辑),requiredTime(可编辑),priority(可编辑),status(不可编辑),base(不可编辑),limit(可编辑)
private JTextField PIDTextField, requiredTimeTextField, priorityTextField, statusTextField;
//CPU状态显示文本域(不可编辑),status信息文本域(用于现实程序每一步的操作和影响,不可编辑)
private JTextArea CPUTextArea, statuesTextArea;
//后备队列PCB数组,就绪、挂起,——内存(可分分区表) PCBRecords backupPCB, readyPCB, suspendedPCB;
public static void main(String[] args) throws IOException { // TODO Auto-generated method stub new SingleCPUSchedulingGUI001().initFrame(); }
public void initFrame() { backupList = new JList(); backupList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); backupList.setVisibleRowCount(BackupBAK_LIST_ROWS); backupList.setFixedCellWidth(BackupBAK_CELL_SIZE); suspendList = new JList(); suspendList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); suspendList.setVisibleRowCount(Suspend_LIST_ROWS); suspendList.setFixedCellWidth(Suspend_CELL_SIZE); readyList = new JList(); readyList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); readyList.setVisibleRowCount(Ready_LIST_ROWS); readyList.setFixedCellWidth(Ready_CELL_SIZE); suspendButton = new JButton(\
addToBAKButton = new JButton(\ addToReadyButton = new JButton(\ resetButton = new JButton(\ umountButton = new JButton(\ removeButton = new JButton(\ startButton = new JButton(\ pauseButton = new JButton(\ resetSyatemButton = new JButton(\ priorityJRB = new JRadioButton(\ timesliceJRB = new JRadioButton(\ backupTotalLabel = new JLabel(\ backupTotalTextField = new JTextField(\ backupTotalTextField.setEditable(false); suspendTotalLabel = new JLabel(\ suspendTotalTextField = new JTextField(\ suspendTotalTextField.setEditable(false); timesliceSizeLabel = new JLabel(\ timesliceJtf = new JTextField(\ timesliceJtf.setEditable(true); CPUTextArea = new JTextArea(CPU_ROWS, CPU_COLS); CPUTextArea.setEditable(false); statuesTextArea = new JTextArea(STATUS_ROWS, STATUS_COLS); statuesTextArea.setEditable(false);
/* north panel*/
// JPanel northPanel = new JPanel(new BorderLayout()); JPanel northPanel = new JPanel(new GridLayout(1, 3)); // JPanel north = new JPanel(new BorderLayout());
// ProcessPCB item information Panel PCBItemPanel = new JPanel(new BorderLayout()); PCBItemPanel.setBorder( BorderFactory.createTitledBorder(\ JPanel PCBItemButtonJPanel = new JPanel(new GridLayout(3, 1)); PCBItemButtonJPanel.add(addToBAKButton); PCBItemButtonJPanel.add(addToReadyButton); PCBItemButtonJPanel.add(resetButton); PCBItemPanel.add(this.initPCBItemPanel(), BorderLayout.CENTER); PCBItemPanel.add(PCBItemButtonJPanel, BorderLayout.SOUTH);
//backupBAKList Panel backupBAKPanel = new JPanel(new BorderLayout()); backupBAKPanel.setBorder(BorderFactory.createTitledBorder(\
JPanel backupTotalPAnel = new JPanel(); backupTotalPAnel.add(backupTotalLabel); backupTotalPAnel.add(backupTotalTextField); backupBAKPanel.add ( new JScrollPane(backupList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED), BorderLayout.CENTER);
backupBAKPanel.add(backupTotalPAnel, BorderLayout.SOUTH);
// north.add(backupBAKPanel, BorderLayout.WEST); // north.add(PCBItemPanel, BorderLayout.CENTER);
// SuspendList Panel
suspendedPanel = new JPanel(new BorderLayout());
suspendedPanel.setBorder(BorderFactory.createTitledBorder(\
JPanel suspendedTotalPAnel = new JPanel(); suspendedTotalPAnel.add(suspendTotalLabel); suspendedTotalPAnel.add(suspendTotalTextField);
JPanel suspendComponentPanel = new JPanel(new GridLayout(1, 2)); suspendComponentPanel.add(umountButton); suspendComponentPanel.add(removeButton);
suspendedPanel.add (suspendedTotalPAnel, BorderLayout.NORTH); suspendedPanel.add ( new JScrollPane(suspendList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED), BorderLayout.CENTER);
suspendedPanel.add(suspendComponentPanel, BorderLayout.SOUTH);
// northPanel.add(north, BorderLayout.CENTER);
// northPanel.add(suspendedPanel, BorderLayout.EAST); northPanel.add(backupBAKPanel); northPanel.add(PCBItemPanel); northPanel.add(suspendedPanel); /* center Panel*/
JPanel centrelPanel = new JPanel(new BorderLayout()); // JPanel centrelPanel = new JPanel(new GridLayout(1, 3));
// readyList panel
JPanel readyListPanel = new JPanel(new BorderLayout());
readyListPanel.setBorder(BorderFactory.createTitledBorder(\ readyListPanel.add ( new JScrollPane(readyList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));//, BorderLayout.CENTER
readyListPanel.add (suspendButton, BorderLayout.SOUTH); // CPU panel
JPanel CPUPanel = new JPanel();
CPUPanel.setBorder(BorderFactory.createTitledBorder(\ CPUPanel.add (new JScrollPane(CPUTextArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
centrelPanel.add(readyListPanel, BorderLayout.WEST); centrelPanel.add(CPUPanel, BorderLayout.CENTER);
/*statues panel*/
JPanel southPanel = new JPanel(new BorderLayout());
JPanel statuesPanel = new JPanel();
statuesPanel.setBorder(BorderFactory.createTitledBorder(\ statuesPanel.add (new JScrollPane(statuesTextArea,
搜索“diyifanwen.net”或“第一范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,第一范文网,提供最新人文社科操作系统实验-CPU进程调度和内存分配 - java版 (3)全文阅读和word下载服务。
相关推荐: