-
大小: 17KB文件類型: .zip金幣: 2下載: 1 次發(fā)布日期: 2021-06-17
- 語言: Java
- 標簽: Java??線程??操作系統(tǒng)??
資源簡介
使用Java實現(xiàn)操作系統(tǒng)中移動臂磁盤調度算法,包括先來先服務調度算法、最短尋找時間優(yōu)先調度算法、電梯調度算法、單向掃描和雙向掃描調度算法,有簡單的圖形用戶界面和通過線程動態(tài)顯示

代碼片段和文件信息
import?java.awt.event.*;
import?javax.swing.*;
import?javax.swing.border.titledBorder;
public?class?ArithPane?extends?JPanel?implements?ActionListener?Runnable?{
/**
?*?
?*/
private?static?final?long?serialVersionUID?=?1L;
JButton?button1?button2?button3?button4?button5?backButton;
JLabel?label;
LogPane?log;
int?now?=?0?max?=?0?meth?=?0;
private?Thread?thread;
private?int?sleeptime?=?1000;
public?ArithPane()?{
//?TODO?自動生成的構造函數存根
try?{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}?catch?(Exception?e)?{
e.printStackTrace();
}
this.setLayout(null);
this.setBorder(new?titledBorder(“模擬移動臂磁盤調度界面“));
log?=?LogPane.getLog();
label?=?new?JLabel(“請選擇以下算法來模擬移動臂磁盤調度:“);
label.setBounds(20?20?350?30);
backButton?=?new?JButton(“返回“);
backButton.setBounds(530?15?80?30);
backButton.addActionListener(this);
button1?=?new?JButton(“先來先服務調度算法“);
button1.setBounds(170?80?250?30);
button1.addActionListener(this);
button2?=?new?JButton(“最短尋找時間優(yōu)先調度算法“);
button2.setBounds(170?120?250?30);
button2.addActionListener(this);
button3?=?new?JButton(“電梯調度算法“);
button3.setBounds(170?160?250?30);
button3.addActionListener(this);
button4?=?new?JButton(“單向掃描調度算法“);
button4.setBounds(170?200?250?30);
button4.addActionListener(this);
button5?=?new?JButton(“雙向掃描調度算法“);
button5.setBounds(170?240?250?30);
button5.addActionListener(this);
this.add(backButton);
this.add(label);
this.add(button1);
this.add(button2);
this.add(button3);
this.add(button4);
this.add(button5);
this.setVisible(true);
}
@Override
public?void?actionPerformed(ActionEvent?e)?{
//?TODO?自動生成的方法存根
if?(e.getSource()?==?backButton)?{
DiskOperation.showCard();
log.addLog(“返回到主界面!“);
meth?=?0;
}
if?(e.getSource()?==?button1)?{
int?len?=?JOptionPane.showConfirmDialog(this?“你選擇的是先來先服務調度算法“?“提示“?JOptionPane.YES_NO_OPTION);
if?(len?==?JOptionPane.OK_OPTION)?{
try?{
String?str?=?JOptionPane.showInputDialog(this?“請輸入當前磁道號“?“提示“?JOptionPane.INFORMATION_MESSAGE);
now?=?Integer.parseInt(str);
log.addLog(“正在模擬先來先服務調度算法...“);
log.addLog(“當前磁道號為:“?+?now);
meth?=?1;
}?catch?(Exception?e1)?{
e1.printStackTrace();
JOptionPane.showMessageDialog(this?“輸入類型錯誤或者未輸入!“?“提示“?JOptionPane.WARNING_MESSAGE);
log.addLog(e1.toString());
}
}
}
if?(e.getSource()?==?button2)?{
int?len?=?JOptionPane.showConfirmDialog(this?“你選擇的是最短尋找時間優(yōu)先算調度算法“?“提示“?JOptionPane.YES_NO_OPTION);
if?(len?==?JOptionPane.OK_OPTION)?{
try?{
String?str?=?JOptionPane.showInputDialog(this?“請輸入當前磁道號“?“提示“?JOptionPane.INFORMATION_MESSAGE);
now?=?Integer.parseInt(str);
log.addLog(“正在模擬最短尋找時間優(yōu)先算調度算法...“);
log.addLog(“當前磁道號為:“?+?now);
meth?=?2;
}?catch?(Exception?e1)?{
e1.printStackTrace();
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-12-29?08:46??Mobile?Arm\
?????文件?????????301??2018-12-29?08:46??Mobile?Arm\.classpath
?????文件?????????386??2018-12-29?08:46??Mobile?Arm\.project
?????目錄???????????0??2018-12-29?08:46??Mobile?Arm\.settings\
?????文件?????????598??2018-12-29?08:46??Mobile?Arm\.settings\org.eclipse.jdt.core.prefs
?????目錄???????????0??2019-01-06?11:11??Mobile?Arm\bin\
?????文件???????13990??2019-01-06?11:11??Mobile?Arm\bin\ArithPane.class
?????文件????????4937??2019-01-06?14:38??Mobile?Arm\bin\DiskOperation.class
?????文件????????1666??2019-01-06?11:11??Mobile?Arm\bin\LogPane.class
?????目錄???????????0??2019-01-03?13:48??Mobile?Arm\src\
?????文件???????18527??2019-01-04?23:47??Mobile?Arm\src\ArithPane.java
?????文件????????3592??2019-01-06?12:25??Mobile?Arm\src\DiskOperation.java
?????文件?????????936??2019-01-03?09:59??Mobile?Arm\src\LogPane.java
評論
共有 條評論