资源简介
银行家算法 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 < resourceClassesCount; 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 < maxNeed.length; i++) {
if (maxNeed[i] < allocated[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两种包
评论
共有 条评论