Implement a COMPLETE GUI application for a pharmacy
using Java as programming language
NO DATABASE BACKEND IS NEEDED
Instead the application should include necessary forms &
functions for below activities :
HR : manage employees, including their leaves and salary
Payroll : manages salary of each employee
Inventory : manages the stock of the pharmacy
Supplier : procurement of medicines
Sales : manages the sales done for each employee
The implementation should also be based on object-oriented concepts, and students are encouraged to investigate additional features and show good problem solving skills.
All necessary programming concepts should be covered, example arrays, functions etc etc
May this help you...
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.table.*;
import java.net.*;
import java.io.*;
import java.sql.*;
class PMSSwing extends JFrame implements ActionListener
{
private Statement st;
private Connection con;
private JLabel lblOldMedID;
private JLabel lblMedID;
private JLabel lblMediTitle;
private JLabel lblQty;
private JLabel lblPrice;
private JTextField txtOldMedID;
private JTextField txtMedID;
private JTextField txtMediTitle;
private JTextField txtQty;
private JTextField txtPrice;
private JButton btnSAdd;
private JButton btnSEdit;
private JButton btnSDelete;
private JButton btnAdd;
private JButton btnEdit;
private JButton btnDelete;
private JButton btnExit;
private JButton btnRef;
private JPanel btnpanel;
private JPanel panel;
private JTable table;
private DefaultTableModel tmodel;
private Container cpane;
PMSSwing()
{ }
PMSSwing(int choice)
{
switch(choice)
{
case 1: setTitle("PHARMACY MANAGEMENT SYSTEM");
setBounds(275, 250, 450, 230);
setResizable(false);
cpane = getContentPane();
tmodel = new DefaultTableModel();
table = new JTable(tmodel);
SetColHeader();
btnpanel = new JPanel(new GridLayout(1, 5, 5, 0));
btnAdd = new JButton ("Add");
btnEdit = new JButton ("Edit");
btnDelete = new JButton ("Delete");
btnRefresh = new JButton ("Refresh");
btnExit = new JButton ("Exit");
btnAdd.addActionListener(this);
btnEdit.addActionListener(this);
btnDelete.addActionListener(this);
btnRefresh.addActionListener(this);
btnExit.addActionListener(this);
btnpanel.add(btnAdd);
btnpanel.add(btnEdit);
btnpanel.add(btnDelete);
btnpanel.add(btnRefresh);
btnpanel.add(btnExit);
cpane.add(new JScrollPane(table));
cpane.add(btnpanel, BorderLayout.SOUTH);
break;
case 2: setTitle("Addition of data...");
setBounds(275, 275, 400, 200);
setResizable(false);
cpane = getContentPane();
cpane.setLayout(new FlowLayout());
panel = new JPanel(new GridLayout(8, 1, 5, 0));
lblMedID = new JLabel(" MediID ");
lblMediTitle = new JLabel(" MediTitle ");
lblQty = new JLabel(" Qty ");
lblPrice = new JLabel(" Price ");
txtMedID = new JTextField(15);
txtMediTitle = new JTextField(15);
txtQty = new JTextField(15);
txtPrice = new JTextField(15);
panel.add(lblMedID);
panel.add(txtMedID);
panel.add(lblMediTitle);
panel.add(txtMediTitle);
panel.add(lblQty);
panel.add(txtQty);
panel.add(lblPrice);
panel.add(txtPrice);
btnpanel = new JPanel(new GridLayout(2, 1, 10, 5));
btnSaveAdd = new JButton ("Save");
btnCancel = new JButton ("Cancel");
btnSaveAdd.addActionListener(this);
btnCancel.addActionListener(this);
btnpanel.add(btnSaveAdd);
btnpanel.add(btnCancel);
cpane.add(panel);
cpane.add(btnpanel, BorderLayout.EAST);
break;
case 3: setTitle("Updation of data...");
setBounds(350, 350, 400, 250);
setResizable(false);
cpane = getContentPane();
cpane.setLayout(new FlowLayout());
panel = new JPanel(new GridLayout(10, 1, 5, 0));
lblOldMedID = new JLabel(" OldMedicineID ");
txtOldMedID = new JTextField(15);
lblMedID = new JLabel(" NewMediID ");
lblMediTitle = new JLabel(" MediTitle ");
lblQty = new JLabel(" Qty ");
lblPrice = new JLabel(" Price ");
txtMedID = new JTextField(15);
txtMediTitle = new JTextField(15);
txtQty = new JTextField(15);
txtPrice = new JTextField(15);
panel.add(lblOldMedID);
panel.add(txtOldMedID);
panel.add(lblMedID);
panel.add(txtMedID);
panel.add(lblMediTitle);
panel.add(txtMediTitle);
panel.add(lblQty);
panel.add(txtQty);
panel.add(lblPrice);
panel.add(txtPrice);
btnpanel = new JPanel(new GridLayout(2, 1, 10, 5));
btnSaveEdit = new JButton ("Save");
btnCancel = new JButton ("Cancel");
btnSaveEdit.addActionListener(this);
btnCancel.addActionListener(this);
btnpanel.add(btnSaveEdit);
btnpanel.add(btnCancel);
cpane.add(panel);
cpane.add(btnpanel, BorderLayout.EAST);
break;
case 4: setTitle("Removal of data...");
setBounds(300, 300, 300, 125);
setResizable(false);
cpane = getContentPane();
cpane.setLayout(new FlowLayout());
panel = new JPanel(new GridLayout(2, 1, 5, 0));
lblMedID = new JLabel("MedicineID to be deleted: ");
txtMedID = new JTextField(15);
panel.add(lblMedID);
panel.add(txtMedID);
btnpanel = new JPanel(new GridLayout(2, 1, 10, 5));
btnSDelete = new JButton ("Delete");
btnCancel = new JButton ("Cancel");
btnSDelete.addActionListener(this);
btnCancel.addActionListener(this);
btnpanel.add(btnSDelete);
btnpanel.add(btnCancel);
cpane.add(panel);
cpane.add(btnpanel, BorderLayout.EAST);
break;
}
setDefaultCloseOperation(HIDE_ON_CLOSE);
setVisible(true);
ConnectToDatabase();
}
public void actionPerformed (ActionEvent ae)
{
if (ae.getSource() == btnAdd)
{
new PMSSwing(2);
}
else if (ae.getSource() == btnEdit)
{
new PMSSwing(3);
}
else if (ae.getSource() == btnDelete)
{
new PMSSwing(4);
}
else if (ae.getSource() == btnExit)
{
System.exit(0);
}
else if (ae.getSource() == btnCancel)
{
setVisible(false);
}
else if(ae.getSource() == btnSaveAdd)
{
AddData(txtMedID.getText(), txtMediTitle.getText(), txtQty.getText(), txtPrice.getText());
txtMedID.setText("");
txtMediTitle.setText("");
txtQty.setText("");
txtPrice.setText("");
}
else if(ae.getSource() == btnSaveEdit)
{
EditData(txtMedID.getText(), txtMediTitle.getText(), txtQty.getText(),txtPrice.getText(), txtOldMediID.getText());
txtOldMedID.setText("");
txtMedID.setText("");
txtMediTitle.setText("");
txtQty.setText("");
txtPrice.setText("");
}
else if(ae.getSource() == btnSaveDelete)
{
DeleteData(txtMedID.getText());
txtMediID.setText("");
}
else if(ae.getSource() == btnRefresh)
{
RetrieveData();
}
}
public static void main(String arg[])
{
PMSSwing c = new PMSSwing(1);
c.RetrieveData();
}
private void SetColHeader()
{
tmodel.addColumn("MedicineID");
tmodel.addColumn("MediTitle");
tmodel.addColumn("Qty");
tmodel.addColumn("Price");
}
private void ConnectToDatabase ()
{
try
{
String dsn = "Medi";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:" + dsn);
st = con.createStatement();
}
catch (Exception e) {System.out.println(e);}
}
private void AddData (String code, String title, String hour, String price)
{
try
{
String qry = "Insert into MediInfo values (?, ?, ?, ?)";
System.out.println(code + "\t"+title+ "\t"+hour+ "\t"+price);
PreparedStatement ps = con.prepareStatement(qry);
ps.setString(1, code);
ps.setString(2, title);
ps.setString(3, hour);
ps.setString(4,price);
ps.executeUpdate();
}
catch(Exception e) {System.out.println(e + "\t" + e.getMessage()); }
}
private void EditData (String code, String title, String hour, String price, String cond)
{
try
{
String qry = "Update MediInfo set MedID = ?, MediTitle = ?, Qty = ?, Price = ? where MedID = ?";
PreparedStatement ps = con.prepareStatement(qry);
ps.setString(1, code);
ps.setString(2, title);
ps.setString(3, hour);
ps.setString(4, price);
ps.setString(5, cond);
ps.executeUpdate();
}
catch(Exception e) {System.out.println(e); }
}
private void DeleteData (String cond)
{
try
{
String qry = "Delete from MediInfo where MedicineID = ?";
PreparedStatement ps = con.prepareStatement(qry);
ps.setString(1, cond);
ps.executeUpdate();
}
catch(Exception e) {System.out.println(e); }
}
private void RetrieveData ()
{
try
{
int row = tmodel.getRowCount();
while(row > 0)
{
row--;
tmodel.removeRow(row);
}
ResultSet rs = st.executeQuery("Select * from MediInfo");
ResultSetMetaData md = rs.getMetaData();
int colcount = md.getColumnCount();
Object[] data = new Object[colcount];
while (rs.next())
{
for (int i=1; i<=colcount; i++)
{
data[i-1] = rs.getString(i);
}
tmodel.addRow(data);
}
}
catch(Exception e) {System.out.println(e); }
}
}
Get Answers For Free
Most questions answered within 1 hours.