亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? simulaterailwaystation.java.bak

?? 通過線程進行通信...火車站售票大廳有許多窗口,有些開放,有些不開放.顧客進去火車站售票大廳后,到某個售票窗口排隊等候,排到了就辦理業務,然后離去.
?? BAK
字號:
import java.util.Date;
import java.awt.*;
import java.awt.event.*;
public class SimulateRailwayStation extends Frame implements ActionListener
{
	protected static final int NUM_AGANTS=10;
    protected static final int NUM_INITIAL_AGANTS=6;
	protected static final int BUSINESS_DELAY=6000;
	protected static final int MAX_TRAIN_NUM=10;
	protected static final int MAX_NO_CUSTOMERS=200;
	private Button  addcus=new Button("添加顧客");
    private Button  delcus=new Button("顧客離去");
	private Button  addagent=new Button("增加售票窗口");
	private Button  delagent=new Button("關閉售票窗口");
	protected static String[]  train_num={"南京->北京,46次","南京->上海,34次","南京->福州,231次","南京->杭州,65次","南京->武漢,112次","南京->成都,77次","南京->天津,21次","南京->徐州,134次","南京->烏魯木齊,335次","南京->合肥,456次"};
	protected static int[]  tickets={50,70,50,50,50,120,60,100,50,50};
	private RailwayStation  railwaystation=new RailwayStation();
	private class WindowCloser extends WindowAdapter
	{
		public void windowClosing(WindowEvent we)
		{
		railwaystation.stop();
		System.exit(0);
		}
	}
	public SimulateRailwayStation()
	{
	super("Simulate RailwayStation");
	Panel buttons=new Panel();
	buttons.setLayout(new FlowLayout());
	buttons.add(addcus);
	buttons.add(delcus);
	buttons.add(addagent);
	buttons.add(delagent);
	addcus.addActionListener(this);
	delcus.addActionListener(this);
	addagent.addActionListener(this);
	delagent.addActionListener(this);
	addWindowListener(new WindowCloser());
	setLayout(new BorderLayout());
	add("North",railwaystation);
	add("South",buttons);
	setSize(500,200);
	validate();
	pack();
	show();
	railwaystation.start();
	}
	public void actionPerformed(ActionEvent ae)
	{
	if(ae.getSource()==addcus)
		{
	railwaystation.generateCustomer();
	}
	else if(ae.getSource()==delcus)
		{
	}
	else if(ae.getSource()==addagent)
		{
	railwaystation.addAgent();
	}
	else if(ae.getSource()==delagent)
		{railwaystation.retireAgent();}
	}
	public static void main(String args[])
	{
	SimulateRailwayStation smlt=new SimulateRailwayStation();
	}
}
class RailwayStation extends Panel implements Runnable
{
	protected Agent[] agent=new Agent[SimulateRailwayStation.NUM_AGANTS];
	protected Label[] labelAgent=new Label[SimulateRailwayStation.NUM_AGANTS];
	protected Label labelQueue=new Label("正在等待的顧客數:0");
	protected Label labelServed=new Label("已經服務的顧客數:0");
	protected int  numAgents=SimulateRailwayStation.NUM_INITIAL_AGANTS;
	public static int numCustomerServered=0;
	private Thread thread=null;
	public RailwayStation()
	{
	setup("各窗口實時狀態顯示:");
	}
	private void setup(String title)
	{
	Panel agentPanel=new Panel();
	agentPanel.setLayout(new GridLayout(SimulateRailwayStation.NUM_AGANTS,1));
	for(int i=0;i<SimulateRailwayStation.NUM_AGANTS;i++)
		{
	if(i<numAgents)
			{
	labelAgent[i]=new Label("窗口"+(i+1)+":空閑中...");
	agentPanel.add(labelAgent[i]);
	agent[i]=new Agent(i);
	agent[i].start();}
	else
				{
	labelAgent[i]=new Label("窗口"+(i+1)+":暫停服務!");
	agentPanel.add(labelAgent[i]);
	}
	}
	Panel otherPanel=new Panel();
	otherPanel.setLayout(new GridLayout(2,1));
	otherPanel.add(labelQueue);
	otherPanel.add(labelServed);
	setLayout(new BorderLayout());
	add("South",agentPanel);
	add("Center",otherPanel);
	add("North",new Label(title));
	}
	public void start()
		{
	if(thread==null)
			{
	thread=new Thread(this);
	thread.start();
	}
	}
	public void run(){
	while(true){
	this.updateDisplay();
	}
	}
	public void updateDisplay()
		{
	int totalSize=0;
	for(int i=0;i<numAgents;i++)
			{
	if(agent[i].getCIdOfHandling()!=0){
	totalSize+=agent[i].getCusCountOfQueue();
	String s="窗口"+(i+1)+":正在辦理顧客"+agent[i].getCIdOfHandling()+"業務";
	if(agent[i].getCusCountOfQueue()>0)
		labelAgent[i].setText(s+"["+agent[i].getCusOfQueue()+"正在等待]");
	else
		labelAgent[i].setText(s);
	}
	else{
	labelAgent[i].setText("窗口"+(i+1)+":空閑中。。。");
	}
	}
	for(int i=numAgents;i<SimulateRailwayStation.NUM_AGANTS;i++)
		labelAgent[i].setText("窗口"+(i+1)+":暫停服務!");
	labelQueue.setText("正在等待的顧客數:"+totalSize);
	labelServed.setText("已經服務的顧客數:"+numCustomerServered);
	}
	public void stop()
		{
	thread=null;
	for(int i=0;i<numAgents;i++)
			{
	agent[i].halt();
	}
	}
	public void addAgent()
		{
	if(numAgents<SimulateRailwayStation.NUM_AGANTS)
			{
	agent[numAgents]=new Agent(numAgents);
	agent[numAgents].start();
	numAgents++;
	}
	}
	public void retireAgent()
		{
	if(numAgents>1)
			{
	agent[numAgents-1].halt();
	numAgents--;
	}
	}
	public void generateCustomer()
		{
	boolean allAgentQueueHasOne=true;
	for(int i=0;i<numAgents;i++)
			{
	if(agent[i].getCusCountOfQueue()==0&&agent[i].getCIdOfHandling()==0)
				{
	agent[i].joinNewCustomer(new Customer());
	allAgentQueueHasOne=false;
	break;
	}
	}
	if(allAgentQueueHasOne)
			{
	int index=0;
	for(int i=0;i<numAgents;i++)
				{
	if(agent[i].getCusCountOfQueue()<agent[index].getCusCountOfQueue())
					{
	index=i;
	}
	}
	agent[index].joinNewCustomer(new Customer());
	}
	}
	}
	class Agent extends Panel implements Runnable
	{
		private boolean running=false;
		private int ID=-1;
		private int numCustomers=0;
		private int handingCId=0;
		private List customersofqueue=new List();
		private List customersofhandled=new List();
		private Label labelHanding=new Label();
		private Label labelThisQueue=new Label();
		private Thread thread=null;
		public Agent(int ID)
		{
		this.ID=ID;
		}
		public void start()
		{
		if(thread==null)
			{
		running=true;
		thread=new Thread(this);
		thread.start();
		}
		}
		public void halt()
		{
		running=false;
		}
		public int getCIdOfHandling()
		{
		return handlingCId;
		}
		public Customer requestCustomerFor()
		{
		if(customersofqueue.getSize()>0)
			{
		Customer c=(Customer)customersofqueue.get(0);
        customersofqueue.delete(0);
		return c;
		}
		else
			{
		return null;
		}
		}
		public int getCusCountOfHandled()
		{
		return numCustomers;
		}
		public String getCusOfHandled()
		{
		if(customersofhandled.getSize()>0)
			{
		StringBuffer sbuf=new StringBuffer();
		sbuf.append("顧客");
		for(int i=0;i<customersofhandled.getSize();i++)
				{
		sbuf.append(((Customer)customersofhandled.get(i)).getCustomerId());
		if(i!=customersofhandled.getSize()-1)
			sbuf.append(",");
		}
		return sbuf.toString();
		}
		else
			{
		return new String("");
		}
		}
       public synchronized void joinNewCustomer(Customer c)
		{
	   if(!customersofqueue.isFull())
			{
	   customersofqueue.add(c);
	   System.out.println("join to agent"+(this.ID+1));
	   }
	   }
       public synchronized String getCusOfQueue()
		{
	   if(customersofqueue.getSize()>0)
			{
	   StringBuffer sbuf=new StringBuffer();
	   sbuf.append("Customer");
	   for(int i=0;i<customersofqueue.getSize();i++)
				{
	   sbuf.append(((Customer)customersofqueue.get(i)).getCustomerId());
	   if(i!=customersofqueue.getSize()-1)
		   sbuf.append(",");
	   }
	   return sbuf.toString();
	   }
	   else
			{
	   return new String("");
	   }
	   }
	   public int getCusCountOfQueue()
		{
	   return customersofqueue.getSize();
	   }
	   public void CustomerLeft()
		{
	   if(customersofqueue.getSize()>0)
		   customersofqueue.delete(customersofqueue.getSize()-1);
	   }
	   public void releaseCustomer(Customer c)
		{
	   numCustomers++;
	   customersofhandled.add(c);
	   }
	   public void run()
		{
	   while(running)
			{
	   try{
	   thread.sleep((int)(Math.random()*SimulateRailwayStation.MAX_NO_CUSTOMERS)+1000);
	   Customer customer=requestCustomerFor();
	   if(customer!=null)
		   {
	   handlingCId=customer.getCustomerId();
	   thread.sleep((int)(Math.random()*SimulateRailwayStation.BUSINESS_DELAY)/2);
	   synchronized(this)
			   {
			   for(int i=0;i<SimulateRailwayStation.train_num.length;i++)
				   {
			   if(customer.getCustomerWilling()==i+1)
				   SimulateRailwayStation.tickets[i]--;
			   }
			   }
			   thread.sleep((int)(Math.random()*SimulateRailwayStation.BUSINESS_DELAY)/2);
			   releaseCustomer(customer);
			   RailwayStation.numCustomerServered+=1;
	   }
	   else
		   {
	   handlingCId=0;
	   }
	   }
	   catch(InterruptedException ie)
				{
	   System.out.println("Teller Exception:"+ie);
	   }
	   }
	   }
	}
	class Customer
	{
		private Date created;
		private static int cId;
		private int customerwilling=0;
		public Customer()
		{
		customerwilling=(int)(Math.random()*10+1);
		created=new Date();
		++cId;
		System.out.print("new Cusomer"+cId+",");
		}
		public int getCustomerId()
		{
		return cId;
		}
		public int getCustomerWilling()
		{
		return customerwilling;
		}
		public long getWaitTime(Date now)
		{
		return now.getTime()-created.getTime();
		}
	}
	class List
	{
		private int maxItems=100;
		private int numItems=0;
		private int ID=-1;
		private Object[] list=null;

		public List()
		{
		list=new Object[maxItems];
		}
		public List(int maxItems)
		{
		this.maxItems=maxItems;
		list=new Object[this.maxItems];
		}
		public void add(Object obj)
		{
		list[numItems++]=obj;
		}
		public void delete(int pos)
		{
		for(int i=pos+1;i<numItems;i++)
			{
		list[i-1]=list[i];
		}
		numItems--;
		}
		public Object get(int pos)
		{
		return list[pos];
		}
		public int getSize()
		{
		return numItems;
		}
		public boolean isFull()
		{
		return(numItems>=maxItems);
		}
	}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产成人欧美日韩在线电影| 奇米影视一区二区三区小说| 久久久久久久久岛国免费| 在线观看日韩高清av| 色哟哟在线观看一区二区三区| 国产一区二区久久| 国产美女精品人人做人人爽| 另类小说视频一区二区| 久久精品国产77777蜜臀| 免费在线看成人av| 久久精品国产一区二区| 极品瑜伽女神91| 国产91丝袜在线18| 91亚洲精华国产精华精华液| 色综合天天做天天爱| 欧美性生活影院| 日韩一区二区三区免费观看| 日韩欧美123| 国产精品网站一区| 亚洲欧美韩国综合色| 亚洲国产视频a| 六月丁香婷婷色狠狠久久| 国产一区二区三区黄视频| 成人性视频免费网站| 色婷婷亚洲综合| 欧美肥大bbwbbw高潮| 精品剧情v国产在线观看在线| 精品欧美黑人一区二区三区| 国产清纯在线一区二区www| 亚洲色图欧洲色图| 日本午夜一本久久久综合| 国产精品99久久久久久有的能看 | 亚洲日本va午夜在线影院| 一区二区三区久久久| 美女视频一区二区三区| 国产白丝网站精品污在线入口| jlzzjlzz亚洲日本少妇| 777久久久精品| 国产亚洲成av人在线观看导航| 亚洲免费观看在线观看| 美国十次了思思久久精品导航| 成人免费高清视频| 777色狠狠一区二区三区| 欧美国产精品一区| 五月激情六月综合| 成人av资源站| 日韩欧美国产高清| 亚洲免费观看视频| 国产成人免费网站| 91精品国产综合久久久久久久久久| 久久久国产一区二区三区四区小说| 亚洲日穴在线视频| 国产一区不卡视频| 91麻豆精品国产| 亚洲啪啪综合av一区二区三区| 麻豆免费精品视频| 欧美日韩久久久久久| 中文字幕不卡的av| 韩国一区二区三区| 91精品国产综合久久久久久 | 不卡av电影在线播放| 在线综合视频播放| 亚洲一区在线看| 91亚洲午夜精品久久久久久| 精品三级在线观看| 免费看黄色91| 欧美日韩国产不卡| 午夜视频久久久久久| 在线观看日韩电影| 亚洲精品午夜久久久| 成a人片亚洲日本久久| 国产欧美日韩视频一区二区| 国产一区二区中文字幕| 欧美一卡二卡在线| 日韩av中文在线观看| 欧美性色aⅴ视频一区日韩精品| 中文字幕一区二区三区在线观看| 韩国三级中文字幕hd久久精品| 欧美另类高清zo欧美| 午夜精品一区二区三区免费视频 | 欧美日韩成人在线| 一区二区三区四区视频精品免费 | 色视频欧美一区二区三区| 中文字幕亚洲欧美在线不卡| 激情欧美一区二区| 久久久天堂av| 床上的激情91.| 国产精品国产三级国产a| 成人免费av资源| 亚洲色图视频网| 欧美三级电影网| 毛片一区二区三区| 国产亚洲欧美日韩日本| 成人黄页毛片网站| 亚洲精品乱码久久久久久黑人 | 欧美日韩在线亚洲一区蜜芽| 亚洲成人综合网站| 欧美高清视频在线高清观看mv色露露十八 | 欧美在线免费播放| 免费在线看成人av| 国产精品丝袜91| 色哟哟日韩精品| 乱一区二区av| 亚洲日本欧美天堂| 91精品欧美久久久久久动漫| 久久99精品国产麻豆婷婷| 国产精品每日更新在线播放网址| 在线免费观看一区| 久久国产尿小便嘘嘘| 国产欧美视频一区二区三区| 99久久精品国产一区二区三区| 亚洲综合免费观看高清完整版 | 国产欧美日韩视频一区二区| 日本乱码高清不卡字幕| 蜜臀a∨国产成人精品| 国产精品剧情在线亚洲| 51精品视频一区二区三区| 国产成人综合亚洲网站| 亚洲与欧洲av电影| 国产精品视频免费| 日韩一级二级三级| 91麻豆蜜桃一区二区三区| 久久99国产精品久久| 亚洲欧美色图小说| 久久理论电影网| 欧美精品日韩精品| 97久久超碰精品国产| 久久99国产精品麻豆| 亚洲第一av色| 亚洲欧美国产三级| 国产精品视频观看| 2020国产精品自拍| 7777精品伊人久久久大香线蕉| eeuss鲁片一区二区三区在线观看 eeuss鲁片一区二区三区在线看 | 成人欧美一区二区三区视频网页| 日韩一区二区三区av| 色域天天综合网| 成人成人成人在线视频| 国产一区二区伦理| 久久电影网电视剧免费观看| 偷拍与自拍一区| 一区二区三区蜜桃网| 中文乱码免费一区二区| 精品国产髙清在线看国产毛片| 欧美日韩亚洲综合在线| 在线观看av一区二区| 97久久超碰精品国产| 成人激情午夜影院| 成人黄色国产精品网站大全在线免费观看| 欧美a一区二区| 免费高清在线一区| 日韩av电影一区| 欧美aa在线视频| 精品中文字幕一区二区小辣椒 | 久久99国产精品免费| 免费在线观看一区| 久久精品72免费观看| 国内成人免费视频| 经典三级一区二区| 国产精品中文字幕一区二区三区| 国模冰冰炮一区二区| 国产一区二区影院| 国产成人av电影在线观看| 国产精一区二区三区| 国产成人免费视频网站| 成人在线综合网站| www.在线欧美| 色偷偷久久人人79超碰人人澡| 91色.com| 欧美日韩国产精品自在自线| 69堂国产成人免费视频| 亚洲精品在线三区| 国产精品卡一卡二| 亚洲一区二区影院| 亚洲成av人片www| 久久99精品国产| 99在线视频精品| 欧美精选在线播放| 精品不卡在线视频| 国产精品福利电影一区二区三区四区| 亚洲欧美成aⅴ人在线观看| 亚洲国产精品一区二区www| 蜜桃视频在线观看一区二区| 国产呦精品一区二区三区网站| 成人免费毛片嘿嘿连载视频| 一本一道久久a久久精品综合蜜臀| 欧美日韩视频在线一区二区| 精品美女被调教视频大全网站| 中日韩免费视频中文字幕| 午夜欧美视频在线观看 | 成人中文字幕合集| 欧美色爱综合网| 久久综合色天天久久综合图片| 国产精品日韩成人| 性做久久久久久免费观看| 国产精品99久久久久久久vr| 在线视频你懂得一区二区三区| 精品国产不卡一区二区三区| 亚洲图片另类小说| 国产乱淫av一区二区三区|