Medical Store
Medical Store
*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.*;
import java.awt.print.PrinterException;
import java.util.ArrayList;
class Medicine {
this.name = name;
this.batchNumber = batchNumber;
this.expiryDate = expiryDate;
this.quantity = quantity;
this.price = price;
public MedicalStoreManagement() {
setSize(800, 600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
headerPanel.setBackground(Color.GREEN);
storeLabel.setForeground(Color.WHITE);
subtitleLabel.setForeground(Color.WHITE);
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);
gbc.gridx = 0; gbc.gridy = 0;
inputPanel.add(nameField, gbc);
gbc.gridx = 0; gbc.gridy = 1;
gbc.gridx = 1;
inputPanel.add(batchField, gbc);
gbc.gridx = 0; gbc.gridy = 2;
gbc.gridx = 1;
inputPanel.add(expiryField, gbc);
gbc.gridx = 0; gbc.gridy = 3;
gbc.gridx = 1;
inputPanel.add(quantityField, gbc);
gbc.gridx = 0; gbc.gridy = 4;
gbc.gridx = 1;
inputPanel.add(priceField, gbc);
gbc.gridx = 2; gbc.gridy = 2;
inputPanel.add(refreshButton, gbc);
buttonPanel.add(addButton);
buttonPanel.add(updateButton);
buttonPanel.add(deleteButton);
buttonPanel.add(viewButton);
searchPanel.setLayout(new GridBagLayout());
gbcSearch.fill = GridBagConstraints.HORIZONTAL;
gbcSearch.gridx = 0; gbcSearch.gridy = 0;
gbcSearch.gridx = 1;
searchPanel.add(searchField, gbcSearch);
gbcSearch.gridx = 0; gbcSearch.gridy = 1;
gbcSearch.gridx = 1;
searchPanel.add(billingField, gbcSearch);
displayArea.setEditable(false);
billPanel.add(billButton);
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);
setVisible(true);
medicines.add(medicine);
viewStock();
tableModel.setRowCount(0);
tableModel.addRow(new Object[]{m.getName(),
m.getBatchNumber(), m.getExpiryDate(), m.getQuantity(), m.getPrice()});
if (m.getName().equalsIgnoreCase(medicineName)) {
selectedMedicine = m;
break;
if (selectedMedicine != null) {
billFrame.setSize(300, 300);
printButton.addActionListener(e -> {
try {
billArea.print();
ex.printStackTrace();
});
billFrame.add(printButton, BorderLayout.SOUTH);
billFrame.setVisible(true);
} else {
JOptionPane.showMessageDialog(this, "Quantity exceeds available
stock!");
} else {
SwingUtilities.invokeLater(MedicalStoreManagement::new);