資源簡介
操作系統期末大作業,用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
評論
共有 條評論