⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simulator.java

📁 java编程开发技巧与实例的编译测试通过的所有例程
💻 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("Open Doors");
	private	Button	close	=	new Button("Close Doors");
	private	Button	add		=	new Button("Add Handler");
	private	Button	del		=	new Button("Del Handler");
	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("Simulation bank vs supermarket");
		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();
		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 + -