clinic appointment system in java

introduction
The Clinic Appointment System is a software application developed in Java to streamline the process of scheduling, managing, and tracking patient appointments in a medical clinic or healthcare facility. This system aims to replace manual appointment booking methods with an efficient, user-friendly digital solution that helps both patients and clinic staff save time and reduce errors.
By automating appointment management, the system facilitates easy registration of patients, scheduling available time slots with doctors, updating appointment details, and maintaining records of past and upcoming visits. It also supports features like patient information storage, doctor availability tracking, and appointment notifications, thereby improving the overall operational efficiency of the clinic.
steps to create clinic appointment system
-
Requirement Analysis
-
Understand what the system should do.
-
Identify key features like patient registration, appointment booking, doctor schedules, appointment updating, and cancellation.
-
-
Design the System
-
Plan the user interface (GUI) layout and workflow.
-
Decide on the user roles (e.g., Receptionist, Doctor, Admin).
-
Design the data structure for storing patient and appointment details (e.g., classes like Patient, Doctor, Appointment).
-
Plan how to store data (in-memory, file-based, or database).
-
-
Set Up Development Environment
-
Install Java Development Kit (JDK).
-
Choose an IDE (NetBeans, Eclipse, IntelliJ IDEA).
-
Set up the project in the IDE.
-
-
Create Java Classes
-
Define the main classes:
-
Patient: Stores patient details (ID, name, contact info).
-
Doctor: Stores doctor details (ID, name, specialization).
-
Appointment: Contains appointment details (appointment ID, patient, doctor, date, time).
-
ClinicManagement: Contains main logic to add, view, update, and delete appointments.
-
-
-
Build the GUI
-
Use Swing or JavaFX to design forms and windows for:
-
Patient registration.
-
Appointment booking.
-
Viewing and managing appointments.
-
-
Add buttons, text fields, dropdowns (combo boxes), and tables as needed.
-
-
Implement Functionality
-
Write methods to:
-
Add new patients.
-
Schedule appointments ensuring no double-booking.
-
Search and update existing appointments.
-
Cancel or delete appointments.
-
-
Add validation (e.g., date/time validation, required fields).
-
-
Data Storage
-
Initially, store data in memory using Lists or Maps.
-
Optionally, implement file handling (text or binary files) or connect to a database (MySQL, SQLite) for persistent data storage.
-
-
Testing
-
Test each feature for correct functionality.
-
Handle edge cases like booking outside clinic hours or duplicate appointments.
-
-
Refinement and Error Handling
-
Add error messages, confirmation dialogs.
-
Improve the user interface for better usability.
-
-
Documentation and Deployment
-
Document the code and user guide.
-
Package the application as a runnable JAR or executable.
-
code explanation
1. Class & JFrame Setup
public class ClinicAppointmentSystem extends JFrame {
-
The class extends
JFrame
to create a window frame for the GUI. -
The constructor
ClinicAppointmentSystem()
sets up the UI components and event handling.
2. UI Components Declaration
private JTextField nameField, ageField;
private JComboBox doctorBox, timeBox;
private JList appointmentList;
private DefaultListModel appointmentModel;
private JSpinner dateSpinner;
-
JTextField
— Input fields for patient’s name and age. -
JComboBox
— Dropdowns to select doctor and time slot. -
JSpinner
— For selecting the appointment date. -
JList
withDefaultListModel
— To display the list of booked appointments.
3. Window Settings
setTitle("🏥 Clinic Appointment System");
setSize(600, 500);
setLayout(null);
getContentPane().setBackground(new Color(245, 255, 250));
setDefaultCloseOperation(EXIT_ON_CLOSE);
-
Sets the window title, size, and layout (absolute positioning).
-
Sets a soft background color.
-
Ensures the application exits when the window closes.
4. Adding Labels and Input Fields
-
Labels for Patient Name, Age, Doctor, Date, Time, with emojis for a friendly UI.
-
Input fields positioned with
.setBounds(x, y, width, height)
for manual layout. -
doctorBox
dropdown filled with example doctors. -
dateSpinner
configured to select dates, formatted as “dd/MM/yyyy”. -
timeBox
dropdown with fixed time slots.
5. Book Appointment Button
JButton bookBtn = new JButton("✅ Book Appointment");
bookBtn.setBounds(180, 290, 200, 35);
bookBtn.setBackground(new Color(102, 205, 170));
bookBtn.setForeground(Color.BLACK);
add(bookBtn);
-
Button to trigger booking.
-
Styled with a greenish background and black text.
6. Appointment List
appointmentModel = new DefaultListModel();
appointmentList = new JList(appointmentModel);
JScrollPane scrollPane = new JScrollPane(appointmentList);
scrollPane.setBounds(50, 340, 480, 100);
add(scrollPane);
-
Displays all booked appointments in a scrollable list below the form.
7. Booking Button ActionListener
bookBtn.addActionListener(e -> {
String patient = nameField.getText();
String age = ageField.getText();
String doctor = doctorBox.getSelectedItem().toString();
Date date = (Date) dateSpinner.getValue();
String time = timeBox.getSelectedItem().toString();
if (patient.isEmpty() || age.isEmpty()) {
JOptionPane.showMessageDialog(this, "Please fill in all fields!");
return;
}
String appointment = "🧾 " + patient + " (" + age + " yrs) with " + doctor +
" on " + new java.text.SimpleDateFormat("dd/MM/yyyy").format(date) + " at " + time;
appointmentModel.addElement(appointment);
JOptionPane.showMessageDialog(this, "Appointment Booked Successfully!");
nameField.setText("");
ageField.setText("");
});
-
When clicked:
-
Reads user input.
-
Validates that name and age are not empty.
-
Formats a string summarizing the appointment details.
-
Adds this string to the list of appointments (
appointmentModel
). -
Shows success message.
-
Clears input fields for new entries.
-
8. Main Method
public static void main(String[] args) {
new ClinicAppointmentSystem();
}
-
Instantiates the GUI by creating an object of the
ClinicAppointmentSystem
class.
source code
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class ClinicAppointmentSystem extends JFrame {
private JTextField nameField, ageField;
private JComboBox doctorBox, timeBox;
private JList appointmentList;
private DefaultListModel appointmentModel;
private JSpinner dateSpinner;
public ClinicAppointmentSystem() {
setTitle("🏥 Clinic Appointment System");
setSize(600, 500);
setLayout(null);
getContentPane().setBackground(new Color(245, 255, 250));
setDefaultCloseOperation(EXIT_ON_CLOSE);
JLabel heading = new JLabel("📅 Book a Doctor's Appointment");
heading.setFont(new Font("Verdana", Font.BOLD, 20));
heading.setBounds(120, 20, 400, 30);
add(heading);
JLabel nameLabel = new JLabel("👤 Patient Name:");
nameLabel.setBounds(50, 80, 120, 25);
add(nameLabel);
nameField = new JTextField();
nameField.setBounds(180, 80, 200, 25);
add(nameField);
JLabel ageLabel = new JLabel("🎂 Age:");
ageLabel.setBounds(50, 120, 100, 25);
add(ageLabel);
ageField = new JTextField();
ageField.setBounds(180, 120, 50, 25);
add(ageField);
JLabel doctorLabel = new JLabel("👨⚕️ Doctor:");
doctorLabel.setBounds(50, 160, 100, 25);
add(doctorLabel);
String[] doctors = {"Dr. Sharma - Dentist", "Dr. Mehta - Cardiologist", "Dr. Roy - Pediatrician"};
doctorBox = new JComboBox(doctors);
doctorBox.setBounds(180, 160, 200, 25);
add(doctorBox);
JLabel dateLabel = new JLabel("📆 Date:");
dateLabel.setBounds(50, 200, 100, 25);
add(dateLabel);
dateSpinner = new JSpinner(new SpinnerDateModel());
dateSpinner.setEditor(new JSpinner.DateEditor(dateSpinner, "dd/MM/yyyy"));
dateSpinner.setBounds(180, 200, 120, 25);
add(dateSpinner);
JLabel timeLabel = new JLabel("⏰ Time:");
timeLabel.setBounds(50, 240, 100, 25);
add(timeLabel);
String[] times = {"10:00 AM", "11:30 AM", "2:00 PM", "4:00 PM"};
timeBox = new JComboBox(times);
timeBox.setBounds(180, 240, 120, 25);
add(timeBox);
JButton bookBtn = new JButton("✅ Book Appointment");
bookBtn.setBounds(180, 290, 200, 35);
bookBtn.setBackground(new Color(102, 205, 170));
bookBtn.setForeground(Color.BLACK);
add(bookBtn);
appointmentModel = new DefaultListModel();
appointmentList = new JList(appointmentModel);
JScrollPane scrollPane = new JScrollPane(appointmentList);
scrollPane.setBounds(50, 340, 480, 100);
add(scrollPane);
bookBtn.addActionListener(e -> {
String patient = nameField.getText();
String age = ageField.getText();
String doctor = doctorBox.getSelectedItem().toString();
Date date = (Date) dateSpinner.getValue();
String time = timeBox.getSelectedItem().toString();
if (patient.isEmpty() || age.isEmpty()) {
JOptionPane.showMessageDialog(this, "Please fill in all fields!");
return;
}
String appointment = "🧾 " + patient + " (" + age + " yrs) with " + doctor +
" on " + new java.text.SimpleDateFormat("dd/MM/yyyy").format(date) + " at " + time;
appointmentModel.addElement(appointment);
JOptionPane.showMessageDialog(this, "Appointment Booked Successfully!");
nameField.setText("");
ageField.setText("");
});
setVisible(true);
}
public static void main(String[] args) {
new ClinicAppointmentSystem();
}
}
output
