📄 simulator.java
字号:
import java.awt.*;
import java.awt.event.*;
public class Simulator
extends Frame
implements ActionListener
{
protected static final int NUM_AGENTS = 10;
protected static final int NUM_INITIAL_AGENTS = 6;
protected static final int MAX_CUSTOMER_DELAY = 9000;
protected static final int MAX_TELLER_BREAK = 1000;
protected static final int MAX_NO_CUSTOMERS = 2000;
private Button open = new Button("开立账户");
private Button close = new Button("取消账户");
private Button add = new Button("添加处理者");
private Button del = new Button("删除处理者");
private Bank bank = new Bank();
private Supermarket supermarket = new Supermarket();
private class WindowCloser
extends WindowAdapter
{
public void windowClosing(WindowEvent we)
{
bank.stop();
supermarket.stop();
System.exit(0);
}
}
public Simulator()
{
super("模拟银行和超市");
Panel buttons = new Panel();
buttons.setLayout(new FlowLayout());
buttons.add(open);
open.addActionListener(this);
buttons.add(close);
close.addActionListener(this);
buttons.add(add);
add.addActionListener(this);
buttons.add(del);
del.addActionListener(this);
addWindowListener(new WindowCloser());
setLayout(new BorderLayout());
add("West", bank);
add("East", supermarket);
add("South", buttons);
validate();
pack();
show();
bank.start();
supermarket.start();
}
public void actionPerformed(ActionEvent ae)
{
if (ae.getSource() == open)
{
bank.openDoor();
supermarket.openDoor();
}
else if (ae.getSource() == close)
{
bank.closeDoor();
supermarket.closeDoor();
}
else if (ae.getSource() == add)
{
bank.addAgent();
supermarket.addAgent();
}
else if (ae.getSource() == del)
{
bank.retireAgent();
supermarket.retireAgent();
}
}
public static void main(String args[])
{
Simulator smlt = new Simulator();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -