Introduction of the Project
Looking to streamline your courier operations? Building a Courier Management System in Java can help! This powerful tool can help you track packages, manage deliveries, and optimize your logistics processes.
To get started, you’ll need to create a Java application that can handle user input and interact with a backend database. For example, we have used SQL database for the same. Then You’ll want to design the GUI of your courier system with scalability in mind so that it can handle a large volume of data and users.
Once you have the basic architecture in place, you can start adding features to your system. Some key functionalities to consider include package tracking, delivery scheduling, route optimization, and real-time notifications.
Objectives
1. To store information regarding the name of the person sending the courier, the location to deliver, and the type & status of the package.
2. To create a user interface that makes this system easy to manage.
3. To implement the tables that contain the courier order information and have the functionality of adding & updating the status of orders.
Requirements
1. knowledge of Java programming language: You should have a good understanding of Java programming language and its libraries, as you will be using Java to build the system.
2. Understanding of Object-Oriented Programming (OOP): You should have a good grasp of OOP concepts such as encapsulation, inheritance, and polymorphism, as you will be using these concepts to design and implement the system.
3. Familiarity with Database Management Systems: You should have a basic understanding of database management systems, as you will be using a database to store and manage the data related to your courier management system.
4. Development Environment: You should have a development environment installed on your computer, such as Eclipse or IntelliJ idea, to develop and test the system.
5. User interface: You need to design a user-friendly interface that allows users to input, view, and manage courier-related data. We have used the Swing module for GUI.
Source Code
package com.company; public class Main { public static void main(String[] args) { new Courier(); } } package com.company; import com.toedter.calendar.JDateChooser; import javax.swing.*; import javax.swing.table.DefaultTableModel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.sql.*; import java.text.DateFormat; import java.util.Vector; public class Courier { private JTextField nameData; private JTextField addressData; private JTable table1; private JButton ADDRECORDButton; private JButton UPDATERECORDButton; private JPanel clinicPanel; private JComboBox status; private JPanel datePanel; private JLabel total; private JComboBox type; private JTextField cost; private JComboBox litres; JFrame clinicF = new JFrame(); JDateChooser dateChooser = new JDateChooser(); public Courier(){ clinicF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); clinicF.setContentPane(clinicPanel); clinicF.pack(); clinicF.setLocationRelativeTo(null); datePanel.add(dateChooser); clinicF.setVisible(true); tableData(); ADDRECORDButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if(nameData.getText().equals("")|| addressData.getText().equals("")|| status.getSelectedItem()==null){ JOptionPane.showMessageDialog(null,"Please Fill All Fields to add Record."); }else{ try { String sql = "insert into courier"+"(SENDER_NAME,SHIPPING_ADDRESS,ESTIMATED_DELIVERY,TYPE,COST,STATUS)"+"values (?,?,?,?,?,?)"; Class.forName("com.mysql.cj.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/intern","root","root"); PreparedStatement statement = connection.prepareStatement(sql); String date= DateFormat.getDateInstance().format(dateChooser.getDate()); statement.setString(1,nameData.getText()); statement.setString(2, addressData.getText()); statement.setString(3, date); statement.setString(4,""+type.getSelectedItem()); statement.setString(5,cost.getText()); statement.setString(6,""+status.getSelectedItem()); statement.executeUpdate(); JOptionPane.showMessageDialog(null,"DETAILS ADDED SUCCESSFULLY"); nameData.setText(""); addressData.setText(""); dateChooser.setCalendar(null); cost.setText(""); }catch (Exception ex){ JOptionPane.showMessageDialog(null,ex.getMessage()); } tableData(); total.setText(String.valueOf(count())); } } }); UPDATERECORDButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try{ String sql = "UPDATE courier " + "SET STATUS = '"+ status.getSelectedItem()+"'"+ " WHERE SENDER_NAME= '"+nameData.getText()+"' AND SHIPPING_ADDRESS= '"+addressData.getText()+"'"; Class.forName("com.mysql.cj.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/intern","root","root"); PreparedStatement statement = connection.prepareStatement(sql); statement.executeUpdate(); JOptionPane.showMessageDialog(null,"Updated successfully"); }catch (Exception e2){ System.out.println(e2); } tableData(); } }); table1.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { DefaultTableModel dm = (DefaultTableModel)table1.getModel(); int selectedRow = table1.getSelectedRow(); nameData.setText(dm.getValueAt(selectedRow,0).toString()); addressData.setText(dm.getValueAt(selectedRow,1).toString()); cost.setText(dm.getValueAt(selectedRow,4).toString()); } }); } public void tableData() { try{ String a= "Select* from courier"; Class.forName("com.mysql.cj.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/intern","root","root"); Statement statement = connection.createStatement(); ResultSet rs = statement.executeQuery(a); table1.setModel(buildTableModel(rs)); }catch (Exception ex1){ JOptionPane.showMessageDialog(null,ex1.getMessage()); } } public static DefaultTableModel buildTableModel(ResultSet rs) throws SQLException { ResultSetMetaData metaData = rs.getMetaData(); // names of columns Vector<String> columnNames = new Vector<String>(); int columnCount = metaData.getColumnCount(); for (int column = 1; column <= columnCount; column++) { columnNames.add(metaData.getColumnName(column)); } // data of the table Vector<Vector<Object>> data = new Vector<Vector<Object>>(); while (rs.next()) { Vector<Object> vector = new Vector<Object>(); for (int columnIndex = 1; columnIndex <= columnCount; columnIndex++) { vector.add(rs.getObject(columnIndex)); } data.add(vector); } return new DefaultTableModel(data, columnNames); } public int count(){ int total = 0; try{ Class.forName("com.mysql.cj.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/intern","root","root"); Statement statement = connection.createStatement(); ResultSet rs = statement.executeQuery("Select COST from courier"); while (rs.next()){ total= total+rs.getInt(1); } }catch (Exception e){ System.out.println(e); } return total; } }
Explanation of the Code
To better understand the implementation of the source code, we have divided it into 2 parts. One involves developing the GUI, and the other is the retrieval of user information from the SQL database for performing the courier services.
Let us look at the GUI first:
1. Our main screen consists of 2 buttons for adding & updating the database.
2. The user interface consists of 4 text fields & 2 Combo Boxes that require information about the customer sending a courier.
3. We have also used a Jlabel “Total Amount” and beside it, there is a Jlabel with the total sum of costs in the database entries.
4. We have also included a Jtable that displays the stored information in the database.
Moving to the retrieval, we will have applied the following
1. The first thing we did was to build a connection with the SQL database using the Connection object.
2. Then we Inject the query that stores table data in ResultSet and send the data to Jtable.
3. Next step is adding & updating functionalities so that it gets updated in the database as well as in the interface.
4. Finally, we are adding a function to retrieve the total cost from all entries in the database and then setting the Jlabel “cost” to that result.
Output
Main Interface
Recommendation
We have successfully built a Java project that helps to manage customer information & help to update the status of couriers. This Java program uses the Swing module for the GUi and is a very efficient & easy way to maintain the data regarding courier orders.
To make your Courier Management System even more effective, you can integrate it with other systems, such as GPS tracking or warehouse management software. This will give you a complete view of your logistics operations, allowing you to make data-driven decisions and optimize your resources.
So if you’re looking to take your courier operations to the next level, consider building a Courier Management System in Java. With the right design and functionality, this tool can help you improve efficiency, reduce costs, and enhance customer satisfaction.

Cisco Ramon is an American software engineer who has experience in several popular and commercially successful programming languages and development tools. He has been writing content since last 5 years. He is a Senior Manager at Rude Labs Pvt. Ltd.
0 Comments