0% found this document useful (0 votes)
3 views10 pages

Medical Store

The document is a Java program that implements a Medical Store Management system using Swing for the graphical user interface. It allows users to add, update, delete, and view medicines, as well as generate bills for purchases. The program manages medicine details such as name, batch number, expiry date, quantity, and price, and provides functionalities for stock management and billing.

Uploaded by

Geetanjali Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views10 pages

Medical Store

The document is a Java program that implements a Medical Store Management system using Swing for the graphical user interface. It allows users to add, update, delete, and view medicines, as well as generate bills for purchases. The program manages medicine details such as name, batch number, expiry date, quantity, and price, and provides functionalities for stock management and billing.

Uploaded by

Geetanjali Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

import javax.swing.

*;

import javax.swing.table.DefaultTableModel;

import java.awt.*;

import java.awt.event.*;

import java.awt.print.PrinterException;

import java.util.ArrayList;

class Medicine {

private String name;

private String batchNumber;

private String expiryDate;

private int quantity;

private double price;

public Medicine(String name, String batchNumber, String expiryDate, int


quantity, double price) {

this.name = name;

this.batchNumber = batchNumber;

this.expiryDate = expiryDate;

this.quantity = quantity;

this.price = price;

public String getName() { return name; }

public void setName(String name) { this.name = name; }

public String getBatchNumber() { return batchNumber; }


public String getExpiryDate() { return expiryDate; }

public int getQuantity() { return quantity; }

public void setQuantity(int quantity) { this.quantity = quantity; }

public double getPrice() { return price; }

public void setPrice(double price) { this.price = price; }

public class MedicalStoreManagement extends JFrame {

private JTextField nameField, batchField, expiryField, quantityField,


priceField, searchField, billingField;

private JButton addButton, updateButton, deleteButton, viewButton,


billButton, refreshButton;

private JTable table;

private DefaultTableModel tableModel;

private JTextArea displayArea;

private ArrayList<Medicine> medicines;

public MedicalStoreManagement() {

medicines = new ArrayList<>();

setTitle("Medical Store Stock Management");

setSize(800, 600);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setLayout(new BorderLayout(10, 10));


JPanel headerPanel = new JPanel();

headerPanel.setBackground(Color.GREEN);

JLabel storeLabel = new JLabel("24 x 7 Medical Store");

storeLabel.setForeground(Color.WHITE);

storeLabel.setFont(new Font("Arial", Font.BOLD, 24));

JLabel subtitleLabel = new JLabel("Chemist and Druggist");

subtitleLabel.setForeground(Color.WHITE);

subtitleLabel.setFont(new Font("Arial", Font.PLAIN, 14));

headerPanel.setLayout(new BoxLayout(headerPanel,
BoxLayout.Y_AXIS));

storeLabel.setAlignmentX(Component.CENTER_ALIGNMENT);

subtitleLabel.setAlignmentX(Component.CENTER_ALIGNMENT);

headerPanel.add(storeLabel);

headerPanel.add(subtitleLabel);

add(headerPanel, BorderLayout.NORTH);

JPanel inputPanel = new JPanel(new GridBagLayout());

GridBagConstraints gbc = new GridBagConstraints();

gbc.insets = new Insets(5, 5, 5, 5);

gbc.gridx = 0; gbc.gridy = 0;

inputPanel.add(new JLabel("Medicine Name:"), gbc);


gbc.gridx = 1;

nameField = new JTextField(15);

inputPanel.add(nameField, gbc);

gbc.gridx = 0; gbc.gridy = 1;

inputPanel.add(new JLabel("Batch Number:"), gbc);

gbc.gridx = 1;

batchField = new JTextField(15);

inputPanel.add(batchField, gbc);

gbc.gridx = 0; gbc.gridy = 2;

inputPanel.add(new JLabel("Expiry Date:"), gbc);

gbc.gridx = 1;

expiryField = new JTextField(15);

inputPanel.add(expiryField, gbc);

gbc.gridx = 0; gbc.gridy = 3;

inputPanel.add(new JLabel("Quantity:"), gbc);

gbc.gridx = 1;

quantityField = new JTextField(15);

inputPanel.add(quantityField, gbc);

gbc.gridx = 0; gbc.gridy = 4;

inputPanel.add(new JLabel("Price:"), gbc);

gbc.gridx = 1;

priceField = new JTextField(15);

inputPanel.add(priceField, gbc);
gbc.gridx = 2; gbc.gridy = 2;

refreshButton = new JButton("Refresh");

inputPanel.add(refreshButton, gbc);

JPanel buttonPanel = new JPanel(new GridLayout(1, 4, 10, 10));

addButton = new JButton("Add Medicine");

updateButton = new JButton("Update Medicine");

deleteButton = new JButton("Delete Medicine");

viewButton = new JButton("View Stock");

buttonPanel.add(addButton);

buttonPanel.add(updateButton);

buttonPanel.add(deleteButton);

buttonPanel.add(viewButton);

JPanel searchPanel = new JPanel();

searchPanel.setLayout(new GridBagLayout());

GridBagConstraints gbcSearch = new GridBagConstraints();

gbcSearch.insets = new Insets(5, 5, 5, 5);

gbcSearch.fill = GridBagConstraints.HORIZONTAL;

gbcSearch.gridx = 0; gbcSearch.gridy = 0;

searchPanel.add(new JLabel("Search by Name:"), gbcSearch);

gbcSearch.gridx = 1;

searchField = new JTextField(15);

searchPanel.add(searchField, gbcSearch);
gbcSearch.gridx = 0; gbcSearch.gridy = 1;

searchPanel.add(new JLabel("Billing (Enter Name):"), gbcSearch);

gbcSearch.gridx = 1;

billingField = new JTextField(15);

searchPanel.add(billingField, gbcSearch);

displayArea = new JTextArea(10, 40);

displayArea.setEditable(false);

JScrollPane displayScrollPane = new JScrollPane(displayArea);

tableModel = new DefaultTableModel(new String[]{"Name", "Batch No.",


"Expiry Date", "Quantity", "Price"}, 0);

table = new JTable(tableModel);

JScrollPane tableScrollPane = new JScrollPane(table);

JPanel billPanel = new JPanel();

billButton = new JButton("Generate Bill");

billPanel.add(billButton);

JPanel centerPanel = new JPanel(new BorderLayout());

centerPanel.add(buttonPanel, BorderLayout.NORTH);

centerPanel.add(searchPanel, BorderLayout.SOUTH);

centerPanel.add(tableScrollPane, BorderLayout.CENTER);

add(inputPanel, BorderLayout.CENTER);

add(centerPanel, BorderLayout.SOUTH);
add(billPanel, BorderLayout.SOUTH);

addButton.addActionListener(e -> addMedicine());

updateButton.addActionListener(e -> updateMedicine());

deleteButton.addActionListener(e -> deleteMedicine());

viewButton.addActionListener(e -> viewStock());

billButton.addActionListener(e -> generateBill());

setVisible(true);

private void addMedicine() {

String name = nameField.getText();

String batchNumber = batchField.getText();

String expiryDate = expiryField.getText();

int quantity = Integer.parseInt(quantityField.getText());

double price = Double.parseDouble(priceField.getText());

Medicine medicine = new Medicine(name, batchNumber, expiryDate,


quantity, price);

medicines.add(medicine);

displayArea.setText("Medicine added successfully!");

viewStock();

private void updateMedicine() {


}

private void deleteMedicine() {

private void viewStock() {

tableModel.setRowCount(0);

for (Medicine m : medicines) {

tableModel.addRow(new Object[]{m.getName(),
m.getBatchNumber(), m.getExpiryDate(), m.getQuantity(), m.getPrice()});

private void generateBill() {

String medicineName = billingField.getText();

Medicine selectedMedicine = null;

for (Medicine m : medicines) {

if (m.getName().equalsIgnoreCase(medicineName)) {

selectedMedicine = m;

break;

if (selectedMedicine != null) {

String quantityStr = JOptionPane.showInputDialog("Enter quantity for


billing:");

int quantity = Integer.parseInt(quantityStr);


if (quantity <= selectedMedicine.getQuantity()) {

double totalPrice = selectedMedicine.getPrice() * quantity;

JTextArea billArea = new JTextArea();

billArea.append("24 x 7 Medical Store\nChemist and Druggist\n\


n");

billArea.append("Medicine: " + selectedMedicine.getName() + "\


n");

billArea.append("Quantity: " + quantity + "\n");

billArea.append("Total Price: " + totalPrice + "\n");

JFrame billFrame = new JFrame("Bill");

billFrame.setSize(300, 300);

billFrame.add(new JScrollPane(billArea), BorderLayout.CENTER);

JButton printButton = new JButton("Print Bill");

printButton.addActionListener(e -> {

try {

billArea.print();

} catch (PrinterException ex) {

ex.printStackTrace();

});

billFrame.add(printButton, BorderLayout.SOUTH);

billFrame.setVisible(true);

} else {
JOptionPane.showMessageDialog(this, "Quantity exceeds available
stock!");

} else {

JOptionPane.showMessageDialog(this, "Medicine not found!");

public static void main(String[] args) {

SwingUtilities.invokeLater(MedicalStoreManagement::new);

You might also like