📄 yinhangjia.java
字号:
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class YinHangJia extends JFrame implements ActionListener, KeyListener {
private JPanel jContentPane = null;
private JMenuBar jJMenuBar = null;
private JMenu fileMenu = null;
private JMenu helpMenu = null;
private JMenuItem aboutMenuItem = null;
private JDesktopPane jDesktopPane1 = null;
private JPanel jPanel1 = null;
private JPanel jPanel2 = null;
private JPanel jPanel3 = null;
private JDesktopPane jDesktopPane2 = null;
private JPanel jPanel1_1 = null;
private JPanel jPanel1_2 = null;
private JPanel jPanel1_3 = null;
private JPanel jPanel1_1_1 = null;
private JPanel jPanel1_1_2 = null;
private JPanel jPanel1_1_3 = null;
private JPanel jPanel1_2_1 = null;
private JPanel jPanel1_2_2 = null;
private JPanel jPanel1_2_3 = null;
private JPanel jPanel1_3_1 = null;
private JPanel jPanel1_3_2 = null;
private JPanel jPanel1_3_3 = null;
private JPanel jPanel3_1 = null;
private JPanel jPanel3_2 = null;
private JPanel jPanel3_3 = null;
private JLabel jLabel1_1_1_1 = null;
private JTextField jTextField1_1_1_1 = null;
private JLabel jLabel1_1_2_1 = null;
private JTextField jTextField1_1_2_1 = null;
private JButton jButton1_1_3_1 = null;
private JLabel jLabel1_2_1_1 = null;
private JButton jButton1_2_3_1 = null;
private JLabel jLabel1_3_1_1 = null;
private JTextField jTextField1_3_1_1 = null;
private JButton jButton1_3_3_1 = null;
private JMenu controlMenu = null;
private JMenuItem startMenuItem = null;
private JMenuItem safecheckMenuItem = null;
private JMenuItem requesMenuItem = null;
int M, N, L;
int[][] max, allocation, need;
int[] work, source, sum, request;
JTextField[] textfield1, textfield2;
String s, s2 = "存在某一安全序列:";
JLabel[] jlabel;
private JLabel jLabel3_1_1 = null;
private JLabel jLabel3_2_1 = null;
private JButton jButton3_3_1 = null;
private JMenuItem flashMenuItem = null;
private JMenuItem exitMenuItem = null;
/**
* This is the default constructor
*/
public YinHangJia() {
super();
initialize();
}
private void initialize() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setJMenuBar(getJJMenuBar());
this.setSize(600, 500);
this.setContentPane(getJContentPane());
this.setTitle("Application");
this.setLocation(270, 150);
}
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJDesktopPane1(), java.awt.BorderLayout.CENTER);
}
return jContentPane;
}
private JMenuBar getJJMenuBar() {
if (jJMenuBar == null) {
jJMenuBar = new JMenuBar();
jJMenuBar.add(getFileMenu());
jJMenuBar.add(getControlMenu());
jJMenuBar.add(getHelpMenu());
}
return jJMenuBar;
}
private JMenu getFileMenu() {
if (fileMenu == null) {
fileMenu = new JMenu();
fileMenu.setText("文件");
fileMenu.add(getStartMenuItem());
fileMenu.add(getExitMenuItem());
}
return fileMenu;
}
private JMenu getHelpMenu() {
if (helpMenu == null) {
helpMenu = new JMenu();
helpMenu.setText("关于");
helpMenu.add(getAboutMenuItem());
}
return helpMenu;
}
private JMenuItem getAboutMenuItem() {
if (aboutMenuItem == null) {
aboutMenuItem = new JMenuItem();
aboutMenuItem.setText("About me");
aboutMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(jContentPane,
"刘力凯 网络(1) 37号", "About me",
JOptionPane.INFORMATION_MESSAGE);
}
});
}
return aboutMenuItem;
}
private JDesktopPane getJDesktopPane1() {
if (jDesktopPane1 == null) {
jDesktopPane1 = new JDesktopPane();
jDesktopPane1.add(getJPanel1(), null);
jDesktopPane1.add(getJPanel2(), null);
jDesktopPane1.add(getJPanel3(), null);
}
return jDesktopPane1;
}
private JPanel getJPanel1() {
if (jPanel1 == null) {
jPanel1 = new JPanel();
jPanel1.setBounds(new java.awt.Rectangle(59, 7, 457, 114));
jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(
java.awt.Color.yellow, 1));
jPanel1.add(getJPanel1_1(), null);
jPanel1.add(getJPanel1_2(), null);
jPanel1.add(getJPanel1_3(), null);
}
return jPanel1;
}
private JPanel getJPanel2() {
if (jPanel2 == null) {
jPanel2 = new JPanel();
jPanel2.setLayout(new BorderLayout());
jPanel2.setBounds(new java.awt.Rectangle(59, 122, 457, 186));
jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(
java.awt.Color.yellow, 1));
jPanel2.add(getJDesktopPane2(), java.awt.BorderLayout.CENTER);
}
return jPanel2;
}
private JPanel getJPanel3() {
if (jPanel3 == null) {
jPanel3 = new JPanel();
jPanel3.setLayout(new BorderLayout());
jPanel3.setBounds(new java.awt.Rectangle(59, 309, 457, 89));
jPanel3.setBorder(javax.swing.BorderFactory.createLineBorder(
java.awt.Color.yellow, 1));
jPanel3.add(getJPanel3_1(), java.awt.BorderLayout.NORTH);
jPanel3.add(getJPanel3_2(), java.awt.BorderLayout.CENTER);
jPanel3.add(getJPanel3_3(), java.awt.BorderLayout.SOUTH);
jPanel3.setVisible(false);
}
return jPanel3;
}
private JDesktopPane getJDesktopPane2() {
if (jDesktopPane2 == null) {
jDesktopPane2 = new JDesktopPane();
jDesktopPane2.setBackground(new java.awt.Color(204, 204, 204));
}
return jDesktopPane2;
}
private JPanel getJPanel1_1() {
if (jPanel1_1 == null) {
jPanel1_1 = new JPanel();
jPanel1_1.setLayout(new BorderLayout());
jPanel1_1.add(getJPanel1_1_1(), java.awt.BorderLayout.NORTH);
jPanel1_1.add(getJPanel1_1_2(), java.awt.BorderLayout.CENTER);
jPanel1_1.add(getJPanel1_1_3(), java.awt.BorderLayout.SOUTH);
jPanel1_1.setVisible(false);
}
return jPanel1_1;
}
private JPanel getJPanel1_2() {
if (jPanel1_2 == null) {
jPanel1_2 = new JPanel();
jPanel1_2.setLayout(new BorderLayout());
jPanel1_2.add(getJPanel1_2_1(), java.awt.BorderLayout.NORTH);
jPanel1_2.add(getJPanel1_2_2(), java.awt.BorderLayout.CENTER);
jPanel1_2.add(getJPanel1_2_3(), java.awt.BorderLayout.SOUTH);
jPanel1_2.setVisible(false);
}
return jPanel1_2;
}
private JPanel getJPanel1_3() {
if (jPanel1_3 == null) {
jPanel1_3 = new JPanel();
jPanel1_3.setLayout(new BorderLayout());
jPanel1_3.add(getJPanel1_3_1(), java.awt.BorderLayout.NORTH);
jPanel1_3.add(getJPanel1_3_2(), java.awt.BorderLayout.CENTER);
jPanel1_3.add(getJPanel1_3_3(), java.awt.BorderLayout.SOUTH);
jPanel1_3.setVisible(false);
}
return jPanel1_3;
}
private JPanel getJPanel1_1_1() {
if (jPanel1_1_1 == null) {
jLabel1_1_1_1 = new JLabel();
jLabel1_1_1_1.setText("JLabel");
jPanel1_1_1 = new JPanel();
jPanel1_1_1.add(jLabel1_1_1_1, null);
jPanel1_1_1.add(getJTextField1_1_1_1(), null);
}
return jPanel1_1_1;
}
private JPanel getJPanel1_1_2() {
if (jPanel1_1_2 == null) {
jLabel1_1_2_1 = new JLabel();
jLabel1_1_2_1.setText("JLabel");
jPanel1_1_2 = new JPanel();
jPanel1_1_2.add(jLabel1_1_2_1, null);
jPanel1_1_2.add(getJTextField1_1_2_1(), null);
}
return jPanel1_1_2;
}
private JPanel getJPanel1_1_3() {
if (jPanel1_1_3 == null) {
jPanel1_1_3 = new JPanel();
jPanel1_1_3.add(getJButton1_1_3_1(), null);
}
return jPanel1_1_3;
}
private JPanel getJPanel1_2_1() {
if (jPanel1_2_1 == null) {
jLabel1_2_1_1 = new JLabel();
jLabel1_2_1_1.setText("JLabel");
jPanel1_2_1 = new JPanel();
jPanel1_2_1.add(jLabel1_2_1_1, null);
}
return jPanel1_2_1;
}
private JPanel getJPanel1_2_2() {
if (jPanel1_2_2 == null) {
jPanel1_2_2 = new JPanel();
}
return jPanel1_2_2;
}
private JPanel getJPanel1_2_3() {
if (jPanel1_2_3 == null) {
jPanel1_2_3 = new JPanel();
jPanel1_2_3.add(getJButton1_2_3_1(), null);
}
return jPanel1_2_3;
}
private JPanel getJPanel1_3_1() {
if (jPanel1_3_1 == null) {
jLabel1_3_1_1 = new JLabel();
jLabel1_3_1_1.setText("JLabel");
jPanel1_3_1 = new JPanel();
jPanel1_3_1.add(jLabel1_3_1_1, null);
jPanel1_3_1.add(getJTextField1_3_1_1(), null);
}
return jPanel1_3_1;
}
private JPanel getJPanel1_3_2() {
if (jPanel1_3_2 == null) {
jPanel1_3_2 = new JPanel();
}
return jPanel1_3_2;
}
private JPanel getJPanel1_3_3() {
if (jPanel1_3_3 == null) {
jPanel1_3_3 = new JPanel();
jPanel1_3_3.add(getJButton1_3_3_1(), null);
}
return jPanel1_3_3;
}
private JPanel getJPanel3_1() {
if (jPanel3_1 == null) {
jLabel3_1_1 = new JLabel();
jLabel3_1_1.setText("");
jPanel3_1 = new JPanel();
jPanel3_1.add(jLabel3_1_1, null);
}
return jPanel3_1;
}
private JPanel getJPanel3_2() {
if (jPanel3_2 == null) {
jLabel3_2_1 = new JLabel();
jLabel3_2_1.setText("");
jPanel3_2 = new JPanel();
jPanel3_2.add(jLabel3_2_1, null);
}
return jPanel3_2;
}
private JPanel getJPanel3_3() {
if (jPanel3_3 == null) {
jPanel3_3 = new JPanel();
jPanel3_3.add(getJButton3_3_1(), null);
}
return jPanel3_3;
}
private JTextField getJTextField1_1_1_1() {
if (jTextField1_1_1_1 == null) {
jTextField1_1_1_1 = new JTextField(4);
jTextField1_1_1_1.setToolTipText("请输入1-6间的整数");
jTextField1_1_1_1.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
if (e.getKeyChar() < KeyEvent.VK_1
|| e.getKeyChar() > KeyEvent.VK_6)
if (e.getKeyChar() != KeyEvent.VK_BACK_SPACE
&& e.getKeyChar() != KeyEvent.VK_ENTER&&e.getKeyChar()!=KeyEvent.VK_DELETE) {
JOptionPane.showMessageDialog(jContentPane,
"请输入0-6之间的数", "输入错误",
JOptionPane.INFORMATION_MESSAGE);
}
}
public void keyReleased(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
}
});
}
return jTextField1_1_1_1;
}
private JTextField getJTextField1_1_2_1() {
if (jTextField1_1_2_1 == null) {
jTextField1_1_2_1 = new JTextField(4);
jTextField1_1_2_1.setToolTipText("请输入1-6间的整数");
jTextField1_1_2_1.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
if (e.getKeyChar() < KeyEvent.VK_1
|| e.getKeyChar() > KeyEvent.VK_6)
if (e.getKeyChar() != KeyEvent.VK_BACK_SPACE
&& e.getKeyChar() != KeyEvent.VK_ENTER&&e.getKeyChar()!=KeyEvent.VK_DELETE) {
JOptionPane.showMessageDialog(jContentPane,
"请输入0-6之间的数", "输入错误",
JOptionPane.INFORMATION_MESSAGE);
}
}
public void keyReleased(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
}
});
}
return jTextField1_1_2_1;
}
private JButton getJButton1_1_3_1() {
if (jButton1_1_3_1 == null) {
jButton1_1_3_1 = new JButton();
jButton1_1_3_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (jTextField1_1_1_1.getText().equals("")
|| jTextField1_1_2_1.getText().equals("")) {
JOptionPane.showMessageDialog(jContentPane, "不能为空",
"提示", JOptionPane.INFORMATION_MESSAGE);
} else {
M = getInt(jTextField1_1_1_1.getText());
N = getInt(jTextField1_1_2_1.getText());
chuShiShuZu();
jPanel1_1.setVisible(false);
shuRuGP1_2();
}
}
});
}
return jButton1_1_3_1;
}
private JButton getJButton1_2_3_1() {
if (jButton1_2_3_1 == null) {
jButton1_2_3_1 = new JButton();
jButton1_2_3_1.addActionListener(this);
}
return jButton1_2_3_1;
}
private JButton getJButton3_3_1() {
if (jButton3_3_1 == null) {
jButton3_3_1 = new JButton();
jButton3_3_1.setText("确定");
jButton3_3_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jPanel3.setVisible(false);
if ((jLabel3_2_1.getText()).equals("It is safe:进行资源分配")) {
thread f = new thread();
f.start();
}
jLabel3_1_1.setText("");
jLabel3_2_1.setText("");
}
});
}
return jButton3_3_1;
}
private JTextField getJTextField1_3_1_1() {
if (jTextField1_3_1_1 == null) {
jTextField1_3_1_1 = new JTextField(1);
}
return jTextField1_3_1_1;
}
private JButton getJButton1_3_3_1() {
if (jButton1_3_3_1 == null) {
jButton1_3_3_1 = new JButton();
jButton1_3_3_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jPanel1_3.setVisible(false);
requestSource();
}
});
}
return jButton1_3_3_1;
}
private JMenu getControlMenu() {
if (controlMenu == null) {
controlMenu = new JMenu();
controlMenu.setText("控制");
controlMenu.add(getSafecheckMenuItem());
controlMenu.add(getRequesMenuItem());
controlMenu.add(getFlashMenuItem());
controlMenu.setEnabled(false);
}
return controlMenu;
}
private JMenuItem getStartMenuItem() {
if (startMenuItem == null) {
startMenuItem = new JMenuItem();
startMenuItem.setText("开始");
startMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
startMenuItem.setText("重新开始");
M = 0;
N = 0;
L = 0;
jPanel1_2_2.removeAll();
jPanel1_3_2.removeAll();
jDesktopPane2.removeAll();
jDesktopPane2.repaint();
jPanel3.setVisible(false);
getControlMenu().setEnabled(false);
shuRuGP1_1();
}
});
}
return startMenuItem;
}
private JMenuItem getSafecheckMenuItem() {
if (safecheckMenuItem == null) {
safecheckMenuItem = new JMenuItem();
safecheckMenuItem.setText("安全检测");
safecheckMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (safeCheck()) {
shuRuGP3();
jLabel3_1_1.setText(s2 + s);
jLabel3_2_1.setText("It is safe:");
} else {
shuRuGP3();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -