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

📄 simulator.java

📁 源程序可使用Jdk1.3以上的任何版本编译和运行主类是Simulator也可以在eclipse环境下直接编译和运行。 顾客队列服务模拟系统
💻 JAVA
字号:
/*
 * 创建日期 2005-2-26
 */
package simulator;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Simulator extends JFrame 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 JButton open = new JButton("Open Doors");

    private JButton close = new JButton("Close Doors");

    private JButton add = new JButton("Add Handler");

    private JButton del = new JButton("Del Handler");

	/**
	 * 
	 * @uml.property name="bank"
	 * @uml.associationEnd multiplicity="(1 1)"
	 */
	private Bank bank = new Bank(); //建立银行和超市对象

	/**
	 * 
	 * @uml.property name="supermarket"
	 * @uml.associationEnd multiplicity="(1 1)"
	 */
	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("Simluation Bank vs Supermarket"); //显示标题
        JPanel buttons = new JPanel(); //创建一个新的面板
        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());
        
        getContentPane().add(bank, BorderLayout.WEST);
        getContentPane().add(supermarket, BorderLayout.EAST);
        getContentPane().add(buttons, BorderLayout.SOUTH);
        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 + -