實(shí)現(xiàn)的功能:
1.病人掛號(hào)使用的客戶端:在界面上選擇想選擇的專家對(duì)應(yīng)的專家號(hào),屏幕上提示掛號(hào)成功,同時(shí)將該病人添加到他所選的專家對(duì)應(yīng)的病人隊(duì)列中。
2.醫(yī)院工作人員使用的客戶端:在界面上單擊相應(yīng)的專家號(hào)就會(huì)在其對(duì)應(yīng)的病人隊(duì)列中取出一位病人,在屏幕上顯示該病人對(duì)應(yīng)的id和名字(防止出現(xiàn)重名的尷尬)并提示到對(duì)應(yīng)的專家處就診。當(dāng)沒有病人時(shí),做出提示。
封裝醫(yī)生類
public class Doctor {
private String ID;
public String getID() {
return ID;
}
public void setID(String iD) {
ID = iD;
}
}
封裝病人類
public class Patient {
private String id;
private String name;
private String doctorID;//病人選擇的專家的ID
public String getDoctorID() {
return doctorID;
}
public void setDoctorID(String doctorID) {
this.doctorID = doctorID;
}
public String getid() {
return id;
}
public void setid(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
掛號(hào)服務(wù)器類
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
public class Hospitalserver {
public Map<String,Queue<Patient>> specialistList = new HashMap<String,Queue<Patient>>();
Queue<Patient> doc1Queue = new LinkedList<Patient>();
Queue<Patient> doc2Queue = new LinkedList<Patient>();
Queue<Patient> doc3Queue = new LinkedList<Patient>();
List<Patient> allPatient = new LinkedList<Patient>();
public void init(){
//實(shí)例化三個(gè)醫(yī)生,其ID就是對(duì)應(yīng)的專家號(hào)
Doctor doc1 = new Doctor();
doc1.setID("01");
Doctor doc2 = new Doctor();
doc2.setID("02");
Doctor doc3 = new Doctor();
doc3.setID("03");
//實(shí)例化6個(gè)病人,并添加到對(duì)應(yīng)的專家隊(duì)列中
Patient aa = new Patient();
aa.setid("001");
aa.setName("joe a");
aa.setDoctorID("01");
doc1Queue.add(aa);
Patient bb = new Patient();
bb.setid("002");
bb.setName("joe b");
aa.setDoctorID("01");
doc1Queue.add(bb);
//********************************************
Patient cc = new Patient();
cc.setid("003");
cc.setName("joe c");
aa.setDoctorID("02");
doc2Queue.add(cc);
Patient dd = new Patient();
dd.setid("004");
dd.setName("joe d");
aa.setDoctorID("02");
doc2Queue.add(dd);
//********************************************
Patient ee = new Patient();
ee.setid("005");
ee.setName("joe e");
aa.setDoctorID("03");
doc3Queue.add(ee);
Patient ff = new Patient();
ff.setid("006");
ff.setName("joe f");
aa.setDoctorID("03");
doc3Queue.add(ff);
specialistList.put(doc1.getID(), doc1Queue);
specialistList.put(doc2.getID(), doc2Queue);
specialistList.put(doc3.getID(), doc3Queue);
}
}
病人使用的客戶端
import java.util.Queue;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class HospitalPatientUI {
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setMaximized(true);
shell.setText("醫(yī)院排隊(duì)之病人使用的客戶度端");
// ------------------新插入的界面核心代碼------------------------
Hospitalserver hospatient = new Hospitalserver();// 實(shí)例化類
hospatient.init();// 初始化隊(duì)列服務(wù)器
final Queue<Patient> doc1Queue = hospatient.specialistList.get("01");
final Queue<Patient> doc2Queue = hospatient.specialistList.get("02");
final Queue<Patient> doc3Queue = hospatient.specialistList.get("03");
final Text patient1Txt = new Text(shell, SWT.MULTI);
patient1Txt.setBounds(100, 50, 200, 150);
final Button patient1button = new Button(shell, SWT.Activate);
patient1button.addSelectionListener(new SelectionAdapter() { // 加一個(gè)選擇監(jiān)聽器
public void widgetSelected(SelectionEvent e) {
//實(shí)例化一個(gè)病人,并添加到他選擇的專家的隊(duì)列中
Patient patient1 = new Patient();
doc1Queue.add(patient1);
patient1Txt.setText("歡迎您選擇一號(hào)專家\n請(qǐng)?jiān)诘却齾^(qū)稍等\n另外請(qǐng)關(guān)注廣播和屏幕通知!");
}
});
patient1button.setBounds(100, 330, 200, 75); // 設(shè)置按鈕位置
patient1button.setFont(new Font(display, "宋體", 12, SWT.BOLD));
patient1button.setText("一號(hào)專家");// 設(shè)置按鈕上的文字
// *****************************************************************
final Text patient2Txt = new Text(shell, SWT.MULTI);
patient2Txt.setBounds(400, 50, 200, 150);
final Button patient2button = new Button(shell, SWT.Activate);
patient2button.addSelectionListener(new SelectionAdapter() { //
public void widgetSelected(SelectionEvent e) {
Patient patient2 = new Patient();
doc1Queue.add(patient2);
patient2Txt.setText("歡迎您選擇二號(hào)專家\n請(qǐng)?jiān)诘却齾^(qū)稍等\n另外請(qǐng)關(guān)注廣播和屏幕通知!");
}
});
patient2button.setBounds(400, 330, 200, 75); // 設(shè)置按鈕位置
patient2button.setFont(new Font(display, "宋體", 12, SWT.BOLD));
patient2button.setText("二號(hào)專家");// 設(shè)置按鈕上的文字
// ***************************************************
final Text patient3Txt = new Text(shell, SWT.MULTI);
patient3Txt.setBounds(700, 50, 200, 150);
final Button patient3button = new Button(shell, SWT.Activate);
patient3button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
Patient patient3 = new Patient();
doc1Queue.add(patient3);
patient3Txt.setText("歡迎您選擇三號(hào)專家\n請(qǐng)?jiān)诘却齾^(qū)稍等\n另外請(qǐng)關(guān)注廣播和屏幕通知!");
}
});
patient3button.setBounds(700, 330, 200, 75); // 設(shè)置按鈕位置
patient3button.setFont(new Font(display, "宋體", 13, SWT.BOLD));
patient3button.setText("三號(hào)專家");// 設(shè)置按鈕上的文字
// ------------------END---------------------------------------------
shell.layout();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
運(yùn)行結(jié)果:
醫(yī)院工作人員使用的客戶端:
import java.util.Queue;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class HospitalWorkerUI {
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setMaximized(true);
shell.setText("醫(yī)院排隊(duì)之醫(yī)院工作人員使用的客戶端");
// ------------------新插入的界面核心代碼------------------------
Hospitalserver qs = new Hospitalserver();//實(shí)例化類
qs.init();//初始化隊(duì)列服務(wù)器
final Queue<Patient> doc1Queue=qs.specialistList.get("01");
final Queue<Patient> doc2Queue=qs.specialistList.get("02");
final Queue<Patient> doc3Queue=qs.specialistList.get("03");
final Text doc1Txt = new Text(shell,SWT.MULTI);
doc1Txt.setBounds(100, 50, 200, 150);
final Button doc1button = new Button(shell, SWT.Activate);
doc1button.addSelectionListener(new SelectionAdapter() { // 加一個(gè)選擇監(jiān)聽器
public void widgetSelected(SelectionEvent e) {
Patient one=doc1Queue.poll();
if(one!=null)
{
doc1Txt.setText("請(qǐng)"+one.getid()+"號(hào)病人"+one.getName()+"到一號(hào)專家處就診,請(qǐng)其他病人稍等。");
}
else
{
doc1Txt.setText("暫時(shí)沒有病人了,請(qǐng)您稍作休息。");
}
}
});
doc1button.setBounds(100, 330, 200, 75); // 設(shè)置按鈕位置
doc1button.setFont(new Font(display,"宋體",12,SWT.BOLD));
doc1button.setText("一號(hào)專家");// 設(shè)置按鈕上的文字
//*****************************************************************
final Text doc2Txt = new Text(shell,SWT.MULTI);
doc2Txt.setBounds(400, 50, 200, 150);
final Button doc2button = new Button(shell, SWT.Activate);
doc2button.addSelectionListener(new SelectionAdapter() { // 加一個(gè)??擇監(jiān)聽器
public void widgetSelected(SelectionEvent e) {
Patient two=doc2Queue.poll();
if(two!=null)
{
doc2Txt.setText("請(qǐng)"+two.getid()+"號(hào)病人"+two.getName()+"請(qǐng)到二號(hào)專家處就診,請(qǐng)其他病人稍等。");
}
else
{
doc2Txt.setText("暫時(shí)沒有病人了,請(qǐng)您稍作休息。");
}
}
});
doc2button.setBounds(400, 330, 200, 75); // 設(shè)置按鈕位置
doc2button.setFont(new Font(display,"宋體",12,SWT.BOLD));
doc2button.setText("二號(hào)專家");// 設(shè)置按鈕上的文字
//***************************************************
final Text doc3Txt = new Text(shell,SWT.MULTI);
doc3Txt.setBounds(700, 50, 200, 150);
final Button doc3button = new Button(shell, SWT.Activate);
doc3button.addSelectionListener(new SelectionAdapter() { // 加一個(gè)??擇監(jiān)聽器
public void widgetSelected(SelectionEvent e) {
Patient three=doc3Queue.poll();
if(three!=null)
{
doc3Txt.setText("請(qǐng)"+three.getid()+"號(hào)病人"+three.getName()+"請(qǐng)到三號(hào)專家處就診,請(qǐng)其他病人稍等。");
}
else
{
doc3Txt.setText("暫時(shí)沒有病人了,請(qǐng)您稍作休息。");
}
}
});
doc3button.setBounds(700, 330, 200, 75); // 設(shè)置按鈕位置
doc3button.setFont(new Font(display,"宋體",13,SWT.BOLD));
doc3button.setText("三號(hào)專家");// 設(shè)置按鈕上的文字
// ------------------END---------------------------------------------
shell.layout();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
運(yùn)行結(jié)果:
不足之處:沒有實(shí)現(xiàn)自動(dòng)判斷病人選擇的專家號(hào);沒有實(shí)現(xiàn)病人使用的客戶端和醫(yī)院工作人員使用的客戶端的同步更新。當(dāng)然還有一些其他的不足,期待您指出并提出完善意見。