实现的功能:

      1.病人挂号使用的客户端:在界面上选择想选择的专家对应的专家号,屏幕上提示挂号成功,同时将该病人添加到他所选的专家对应的病人队列中。

      2.医院工作人员使用的客户端:在界面上单击相应的专家号就会在其对应的病人队列中取出一位病人,在屏幕上显示该病人对应的id和名字(防止出现重名的尴尬)并提示到对应的专家处就诊。当没有病人时,做出提示。

封装医生类

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;
    }
}

挂号服务器类

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(){
        //实例化三个医生,其ID就是对应的专家号
        Doctor doc1 = new Doctor();
        doc1.setID("01");
        Doctor doc2 = new Doctor();
        doc2.setID("02");
        Doctor doc3 = new Doctor();
        doc3.setID("03");
        //实例化6个病人,并添加到对应的专家队列中
        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("医院排队之病人使用的客户度端");
        // ------------------新插入的界面核心代码------------------------
        Hospitalserver hospatient = new Hospitalserver();// 实例化类
        hospatient.init();// 初始化队列服务器
        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() { // 加一个选择监听器
                    public void widgetSelected(SelectionEvent e) {
                        //实例化一个病人,并添加到他选择的专家的队列中
                        Patient patient1 = new Patient();
                        doc1Queue.add(patient1);
                        patient1Txt.setText("欢迎您选择一号专家\n请在等待区稍等\n另外请关注广播和屏幕通知!");
                    }
                });

        patient1button.setBounds(100, 330, 200, 75); // 设置按钮位置
        patient1button.setFont(new Font(display, "宋体", 12, SWT.BOLD));
        patient1button.setText("一号专家");// 设置按钮上的文字

        // *****************************************************************

        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("欢迎您选择二号专家\n请在等待区稍等\n另外请关注广播和屏幕通知!");
                    }
                });
        patient2button.setBounds(400, 330, 200, 75); // 设置按钮位置
        patient2button.setFont(new Font(display, "宋体", 12, SWT.BOLD));
        patient2button.setText("二号专家");// 设置按钮上的文字

        // ***************************************************

        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("欢迎您选择三号专家\n请在等待区稍等\n另外请关注广播和屏幕通知!");
                    }
                });
        patient3button.setBounds(700, 330, 200, 75); // 设置按钮位置
        patient3button.setFont(new Font(display, "宋体", 13, SWT.BOLD));
        patient3button.setText("三号专家");// 设置按钮上的文字

        // ------------------END---------------------------------------------
        shell.layout();
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }

    }
}

运行结果:

image

医院工作人员使用的客户端:

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("医院排队之医院工作人员使用的客户端");
            // ------------------新插入的界面核心代码------------------------
            Hospitalserver qs = new Hospitalserver();//实例化类
            qs.init();//初始化队列服务器
            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() { // 加一个选择监听器
                        public void widgetSelected(SelectionEvent e) {
                                        Patient one=doc1Queue.poll();
                                        if(one!=null)
                                        {
                                            doc1Txt.setText("请"+one.getid()+"号病人"+one.getName()+"到一号专家处就诊,请其他病人稍等。");
                                        }
                                        else
                                        {
                                            doc1Txt.setText("暂时没有病人了,请您稍作休息。");
                                        }
                                    }
                                });

            doc1button.setBounds(100, 330, 200, 75); // 设置按钮位置
            doc1button.setFont(new Font(display,"宋体",12,SWT.BOLD));
            doc1button.setText("一号专家");// 设置按钮上的文字
            //*****************************************************************

            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() { // 加一个�?择监听器
                        public void widgetSelected(SelectionEvent e) {

                            Patient two=doc2Queue.poll();
                            if(two!=null)
                            {
                                doc2Txt.setText("请"+two.getid()+"号病人"+two.getName()+"请到二号专家处就诊,请其他病人稍等。");
                            }
                            else
                            {
                                doc2Txt.setText("暂时没有病人了,请您稍作休息。");
                            }
                        }
                    });
            doc2button.setBounds(400, 330, 200, 75); // 设置按钮位置
            doc2button.setFont(new Font(display,"宋体",12,SWT.BOLD));
            doc2button.setText("二号专家");// 设置按钮上的文字
            //***************************************************

            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() { // 加一个�?择监听器
                        public void widgetSelected(SelectionEvent e) {
                             Patient three=doc3Queue.poll();
                                if(three!=null)
                                {
                                    doc3Txt.setText("请"+three.getid()+"号病人"+three.getName()+"请到三号专家处就诊,请其他病人稍等。");
                                }
                                else
                                {
                                    doc3Txt.setText("暂时没有病人了,请您稍作休息。");
                                }
                            }
                        });
            doc3button.setBounds(700, 330, 200, 75); // 设置按钮位置
            doc3button.setFont(new Font(display,"宋体",13,SWT.BOLD));
            doc3button.setText("三号专家");// 设置按钮上的文字

            // ------------------END---------------------------------------------
            shell.layout();
            shell.open();
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch())
                    display.sleep();
            }
        }
}

运行结果:

image

     不足之处:没有实现自动判断病人选择的专家号;没有实现病人使用的客户端和医院工作人员使用的客户端的同步更新。当然还有一些其他的不足,期待您指出并提出完善意见。