Over a million developers have joined DZone.

GUI Tool for Patient/Doctor Scheduling

DZone's Guide to

GUI Tool for Patient/Doctor Scheduling

· Java Zone
Free Resource

Managing a MongoDB deployment? Take a load off and live migrate to MongoDB Atlas, the official automated service, with little to no downtime.

Let's create a GUI tool for scheduling doctors to patients:

The most important part of this tool is the ability to schedule doctors to time slots for patients. The workflow is that the user drags a doctor and drops it over a morning slot or afternoon slot for a specific patient. On the drop, the patient table is updated to show the newly assigned doctor, replacing the doctor that had been assigned prior to the drop.

All the rest of the above is standard NetBeans Platform stuff. A first attempt to drag from the BeanTreeView onto a Node in the OutlineView failed to achieve the desired result because the Node doesn't know about the view and hence doesn't know the location in the view where the drop occurs.

Therefore, the drop handling needs to be set on... the view:

private class PatientOutlineView extends OutlineView {

    Outline outline;

    public PatientOutlineView() {
        outline = getOutline();
        DropTarget dt = new DropTarget(outline, new PatientOutlineViewDropTargetListener());

    public class PatientOutlineViewDropTargetListener implements DropTargetListener {

        public void drop(DropTargetDropEvent dtde) {
            Point locationOfDrop = dtde.getLocation();
            Node doctorNode = NodeTransfer.node(
            Doctor doctor = doctorNode.getLookup().lookup(Doctor.class);
            if (doctor != null) {
                int columnAtPoint = outline.columnAtPoint(locationOfDrop);
                int rowAtPoint = outline.rowAtPoint(locationOfDrop);
                if (columnAtPoint != 0) {
                    outline.setValueAt(doctor.getName(), rowAtPoint, columnAtPoint);
                    outline.setRowSelectionInterval(rowAtPoint, rowAtPoint);
                    Node currentPatientNode = getExplorerManager().getSelectedNodes()[0];
                    Patient currentPatient = currentPatientNode.getLookup().lookup(Patient.class);
                    StringBuilder messageBuilder = new StringBuilder();
                    messageBuilder.append("Assigned ").append(doctor.getName()).append(" to ").append(
                    if (columnAtPoint == 1) {
                        messageBuilder.append(" for the morning slot");
                    } else if (columnAtPoint == 2) {
                        messageBuilder.append(" for the afternoon slot");
                } else {
                            "Cannot drop " + doctor.getName() + " at "
                            + rowAtPoint + " / " + columnAtPoint
                            + " because that's the Patients column");

        public void dragEnter(DropTargetDragEvent dtde) {

        public void dragExit(DropTargetEvent dtde) {

        public void dragOver(DropTargetDragEvent dtde) {

        public void dropActionChanged(DropTargetDragEvent dtde) {



There's at least one problem with this solution. When the user changes the position of the columns, the 0/0 row/column could be in a different place and then the doctor could be dropped on top of the patient, instead of on top of the currently assigned doctor. Aside from that, which can still be resolved somehow, the above is workable solution.

The complete source code of this example can be downloaded here:


MongoDB Atlas is the easiest way to run the fastest-growing database for modern applications — no installation, setup, or configuration required. Easily live migrate an existing workload or start with 512MB of storage for free.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}