实现的功能:

      1.银行工作人员使用的客户端实现功能:每次单击Button“下一个”,窗口上会显示提示X号顾客去y号窗口办理业务;当顾客队列里没有顾客时对工作人员作出提示。

      2.顾客使用的客户端实现功能:每当有顾客单击Button“个人业务”,窗口上会显示当前顾客在队伍中的位置以及他的前面还有多少位顾客,当排在当前顾客前面的顾客人数超过50人时提示前面已经有50个人,是否继续等候。关于这个金卡通道嘛,现在流行各种会员啊VIP啦等等,这个金卡通道当然就是为银行的VIP准备的。当单击Button“金卡通道”时,将当前Waiter添加到顾客队列的首位并在窗口上显示无需等待~~。

代码如下:

      封装顾客类。

public class Waiter {

    private int num;         //顾客号
    private int frontNum;  //排在前面的人数
    private int flag;          //卡类型

    public int getFlag() {
        return flag;
    }

    public void setFlag(int flag) {
        this.flag = flag;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public int getFrontNum() {
        return frontNum;
    }

    public void setFrontNum(int frontNum) {
        this.frontNum = frontNum;
    }
}

 

初始化顾客队列(30个人)。

import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

public class QueueServer {

    LinkedList<Waiter> waiterList = new LinkedList<Waiter>();
    public LinkedList<Waiter> init(){
        for(int i=1;i<=30;i++){
            Waiter w = new Waiter();
            w.setNum(i);
            w.setFrontNum(i-1);
            waiterList.offer(w);
        }
        return waiterList;
    }
}

 

顾客使用的客户端:

import java.util.LinkedList;

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 Swtgoldcard {
        public static void main(String[] args) {
            final Display display = Display.getDefault();
            final Shell shell = new Shell();
            shell.setMaximized(true);
            shell.setText("银行排队系统之金卡插队");
            // ------------------新插入的界面核心代码------------------------
            QueueServer qs = new QueueServer();//实例化顾客队列类
            final LinkedList<Waiter> waiterList = qs.init();//初始化队列服务器
            final Text txt = new Text(shell,SWT.MULTI);
            txt.setBounds(40, 50, 500, 450);
            final Button button = new Button(shell, SWT.Activate);
            button.addSelectionListener(new SelectionAdapter() { // 加一个选择监听器
                        public void widgetSelected(SelectionEvent e) {
                            //System.out.println("############### " + waiterList.size());
                            Waiter waiter = new Waiter();                       
                            waiter.setNum(waiterList.size()+1);
                            waiter.setFrontNum(waiterList.size());
                            waiterList.offer(waiter);
                            if(waiterList.size() <= 50){
                                txt.setText( "您现在排在"+waiter.getNum()+"位置上\n您前面有"+waiter.getFrontNum()+"个人\n请您耐心等候!");
                            }else{
                                txt.setText("您前面已经排50个人\n请考虑是否继续等待!\n"+"您现在排在"+waiter.getNum()+"位置上\n您前面有"+waiter.getFrontNum()+"个人\n请您耐心等候!");
                            }
                        }
            });
            button.setBounds(180, 530, 200, 75); // 设置按钮位置
            button.setFont(new Font(display,"宋体",12,SWT.BOLD));
            button.setText("个人业务");// 设置按钮上的文字

 


            //金卡通道
            final Text goldTxt = new Text(shell,SWT.MULTI);
            goldTxt.setBounds(900, 50, 500, 450);
            final Button goldButton = new Button(shell, SWT.Activate);
            goldButton.addSelectionListener(new SelectionAdapter() { // 加一个选择监听器
                        public void widgetSelected(SelectionEvent e) {
                            Waiter goldWaiter = new Waiter();
                            goldWaiter.setFlag(1);
                            waiterList.addFirst(goldWaiter);                       
                            goldTxt.setText("您是金卡用户\n可以优先接受服务\n无需等待!\n"+"您现在排在"+goldWaiter.getNum()+"位置上,\n您前面有"+goldWaiter.getFrontNum()+"个人");
                        }
            });
            goldButton.setBounds(1060, 530, 200, 75); // 设置按钮位置
            goldButton.setFont(new Font(display,"宋体",12,SWT.BOLD));
            goldButton.setText("金卡通道");// 设置按钮上的文字

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

        }

运行结果:

image

当等待队列中人数超过50人时显示结果:

image

 

银行工作人员使用的客户端:

import java.util.Queue;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
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 BankWorkerUI {
    public static void main(String[] args) {
        final Display display = Display.getDefault();
        final Shell shell = new Shell();
        shell.setSize(352, 253);
        shell.setText("银行排队系统之工作人员客户端");
        // ------------------新插入的界面核心代码------------------------
        QueueServer qs = new QueueServer();//实例化类
        final Queue<Waiter> waiterList = qs.init();//初始化队列服务器
        final Text txt = new Text(shell,SWT.MULTI);
        txt.setBounds(65, 30, 220, 70);
        final Button button = new Button(shell, SWT.Activate);
        button.addSelectionListener(new SelectionAdapter() { // 加一个选择监听器
                    public void widgetSelected(SelectionEvent e) {
                        //System.out.println("############### " + waiterList.size());
                        Waiter waiter= waiterList.poll();
                        if(waiter!= null){
                          txt.setText(waiter.getNum()+"号顾客请到1号窗口办理业务");
                        }else{
                            txt.setText("暂时没有顾客要办理业务,您可以休息一下!\n ");
                        }
                    }
                });
        button.setBounds(120, 141, 100, 25); // 设置按钮位置
        button.setText("下一个");// 设置按钮上的文字

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

运行结果:

image

这个程序还有缺陷,没有用到数据库,无法实现工作人员所用的客户端与顾客所用的客户端同步更新,请高手指点完善。