資源簡介
銀行家算法 java 圖形界面 模塊化編程 算法簡單 安全性算法需要優化。

代碼片段和文件信息
import?java.awt.GridLayout;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?javax.swing.JButton;
import?javax.swing.JDialog;
import?javax.swing.Jframe;
import?javax.swing.JLabel;
import?javax.swing.JOptionPane;
import?javax.swing.JPanel;
import?javax.swing.JTextField;
public?class?AddProcess?extends?JDialog?implements?ActionListener?{
private?static?final?long?serialVersionUID?=?-4063443304983396100L;
public?static?boolean?InputEffiencent?=?true;
public?static?boolean?InputError?=?false;
private?JButton?okButton;
private?JButton?cancelButton;
private?JTextField?processName;
private?JTextField[]?textMaxNeed;
private?JTextField[]?textAllocated;
private?int[]?maxNeed?=?null;
private?int[]?allocated?=?null;
private?String?name;
private?boolean?returnResult?=?InputError;?//?InputEffiencent?InputError.
private?final?int?lineHeight?=?35;
private?final?int?width?=?65;
public?AddProcess(Jframe?owner?int?resourceClassesCount)?{
super(owner?“添加新進程“?true);
textMaxNeed?=?new?JTextField[resourceClassesCount];
textAllocated?=?new?JTextField[resourceClassesCount];
maxNeed?=?new?int[resourceClassesCount];
allocated?=?new?int[resourceClassesCount];
processName?=?new?JTextField();
JPanel?panel?=?new?JPanel(new?GridLayout(resourceClassesCount?+?3?3));
panel.add(new?JLabel(“進程名“));
panel.add(processName);
panel.add(new?JLabel());?//?站位作用.
panel.add(new?JLabel(“資源名“));?//?站位作用.
panel.add(new?JLabel(“最大需求“));
panel.add(new?JLabel(“已分配“));
for?(int?i?=?0;?i? String?resourceName?=?“資源R“?+?String.valueOf(i)?+?“:“;
panel.add(new?JLabel(resourceName));
textMaxNeed[i]?=?new?JTextField();
panel.add(textMaxNeed[i]);
textAllocated[i]?=?new?JTextField();
panel.add(textAllocated[i]);
}
panel.add(new?JLabel());?//?站位作用.
okButton?=?new?JButton(“確定“);
okButton.addActionListener(this);
panel.add(okButton);
cancelButton?=?new?JButton(“取消“);
cancelButton.addActionListener(this);
panel.add(cancelButton);
this.getContentPane().add(panel);
setBounds();
}
public?void?setBounds()?{
this.setBounds(getX()?getY()?width?*?3?+?width?+?100?lineHeight
*?(textMaxNeed.length?+?3));
this.setLocationRelativeTo(this.getOwner());
}
private?void?setProcess()?{
if?(setName()?&&?setMaxNeed()?&&?setAllocated())?{
for?(int?i?=?0;?i? if?(maxNeed[i]? returnResult?=?InputError;
JOptionPane.showMessageDialog(this?“進程已分配資源量大于進程所需資源最大量!“);
return;
}
}
returnResult?=?InputEffiencent;
}
}
private?boolean?setName()?{
returnResult?=?InputEffiencent;
name?=?processName.getText().trim();
if?(name.isEmpty())?{
JOptionPane.showMessageDialog(this?“進程名不能為空!“);
returnResult?=?InputError;
return?returnResult;
}
processName.setText(““);
return?returnResult;
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-01-10?17:47??OSKS_Banker?Algorithm\
?????文件?????????301??2014-01-07?03:38??OSKS_Banker?Algorithm\.classpath
?????文件?????????397??2018-01-07?15:54??OSKS_Banker?Algorithm\.project
?????目錄???????????0??2018-01-10?17:47??OSKS_Banker?Algorithm\.settings\
?????文件?????????598??2014-01-07?03:38??OSKS_Banker?Algorithm\.settings\org.eclipse.jdt.core.prefs
?????目錄???????????0??2018-01-10?17:47??OSKS_Banker?Algorithm\bin\
?????文件????????5116??2018-01-10?17:47??OSKS_Banker?Algorithm\bin\AddProcess.class
?????文件????????3921??2018-01-10?17:47??OSKS_Banker?Algorithm\bin\AddResource.class
?????文件???????10939??2018-01-10?17:47??OSKS_Banker?Algorithm\bin\BankerMainUI.class
?????文件????????8806??2018-01-10?17:47??OSKS_Banker?Algorithm\bin\BankersAlgorithm.class
?????文件????????4239??2018-01-10?17:47??OSKS_Banker?Algorithm\bin\RequestResource.class
?????文件????????4514??2018-01-10?17:47??OSKS_Banker?Algorithm\bin\SystemProcess.class
?????目錄???????????0??2018-01-10?17:47??OSKS_Banker?Algorithm\src\
?????文件????????4962??2018-01-07?22:24??OSKS_Banker?Algorithm\src\AddProcess.java
?????文件????????3207??2018-01-08?08:56??OSKS_Banker?Algorithm\src\AddResource.java
?????文件???????12334??2018-01-08?09:42??OSKS_Banker?Algorithm\src\BankerMainUI.java
?????文件????????8162??2018-01-08?10:44??OSKS_Banker?Algorithm\src\BankersAlgorithm.java
?????文件????????3411??2014-01-07?04:20??OSKS_Banker?Algorithm\src\RequestResource.java
?????文件????????3975??2018-01-08?09:54??OSKS_Banker?Algorithm\src\SystemProcess.java
- 上一篇:java生成十個不重復的隨機數
- 下一篇:aliyun-java.jar兩種包
評論
共有 條評論