资源简介
操作系统期末大作业,用java语言解决理发师问题,而且还是有界面的,里面有源代码
代码片段和文件信息
package ymm.barber;
import ymm.barber.Barbershop;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class Barber implements Runnable{
Barbershop bs;
Window win;
JTextArea textArea;
int count;
JTextField chair1chair2chair3;
public Barber (Barbershop bsint iWindow window) {
win = window;
this.textArea = win.textArea;
this.chair1 = win.chair1;
this.chair2 = win.chair2;
this.chair3 = win.chair3;
this.bs = bs;
count = i;
}
public void run() {
Barbershop.customers++;
textArea.append( “The customer“+count+“ is coming!\r\n“);
if (count == 1)
textArea.append(“The customer1 wakes the barber up!\r\n“);
if (bs.isFull()){
Barbershop.customers--;
JOptionPane.showMessageDialog(win.frmBarbershop “Sorry! No empty seats!“ “信息“ JOptionPane.INFORMATION_MESSAGE);
textArea.append(“The customer“+count+“ leaves\r\n“);
}else {
if (Barbershop.barber == 1)
{
textArea.append(“The customer“+count+“ is waiting for the barber!\r\n“);
if (chair1.getText().length()<1)
chair1.setText(“customer“+count);
else if(chair2.getText().length()<1)
chair2.setText(“customer“+count);
else
chair3.setText(“customer“+count);
}
try {
Barbershop.mutex.acquire();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
synchronized (this) {
while (Barbershop.barber == 1)
try {
wait();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
if (Barbershop.customers == 1)
textArea.append(“Only customer“+count+“ is in the barbershop and the barber is awake!\r\n“);
Barbershop.barber = 1;
textArea.append(“The customer“+count+“ is having his hair cut!\r\n“);
textArea.append(“Please wait for fifteen minutes!\r\n“);
try {
Thread.sleep(3000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
textArea.append(“The customer“+count+“ has his hair cut and leaves\r\n“);
Barbershop.customers--;
chair1.setText(““);
chair1.setText(chair2.getText());
chair2.setText(chair3.getText());
chair3.setText(““);
Barbershop.mutex.release();
synchronized(this) {
Barbershop.barber = 0;
notify();
}
if (Barbershop.customers == 0) {
textArea.append(“There is no customer and the barber start to sleep!\r\n“);
}
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2635 2017-04-23 20:23 操作系统-理发师问题\barber shop源代码\Barber.java
文件 813 2017-04-23 20:20 操作系统-理发师问题\barber shop源代码\Barbershop.java
文件 3958 2017-04-23 22:52 操作系统-理发师问题\barber shop源代码\Window.java
文件 6743 2017-04-23 20:31 操作系统-理发师问题\BARBERSHOP.jar
文件 332 2017-04-26 18:48 操作系统-理发师问题\ReadMe.txt
目录 0 2017-04-23 18:20 操作系统-理发师问题\barber shop源代码
目录 0 2017-12-06 15:47 操作系统-理发师问题
----------- --------- ---------- ----- ----
14481 7
相关资源
- java 动态获取数据库信息生成word(含
- 神州另一套笔试题JAVA
- mysql-connector-java-5.1.9.jar
- Spark大数据中文分词统计Java工程源码
- 中国象棋源码JAVA版,很详细
- smali文件编译java文件
- java jar包jbig转bmp
- Java语音聊天
- JAVA netty 获取串口数据并且下发数据
- java课程设计-拿火柴游戏
- 基于web的员工工资管理系统毕业论文
- 用java编写的科学计算器
- Java编程思想第4版源代码+习题答案
- 名片管理系统(jsp+Struts+javabean)
- java版通讯录管理系统
- java求圆周率PI的值 蒙特卡洛方法
- cache模拟器
- javaxmail jar包
- 局域网坦克大战源码Java版
- java加数据库的网吧管理系统
- javaweb英语论文原文+翻译
- 基于java的视频中车辆的标记
- rabbitmq:基于java、基于springboot、基于
- 微信公众平台的开发java——视频教程
- 根据关键字查找文件,可查找(*.ja
- java局域网聊天+文件传输系统
- java实现文字转语音文件和朗读
- 经典DBN代码详解JAVA版
- JavaMail帐号激活与忘记密码
- java屏幕录像(包含鼠标轨迹)生成
评论
共有 条评论