The Touchable Shop POS (Point of Sale) system is a sophisticated software solution developed using Java. Designed specifically for fruit shops, this system efficiently manages sales and transactions, ensuring smooth and streamlined operations. With its user-friendly interface and robust functionality, the Touchable Shop POS system is an essential tool for modern fruit retailers.
The system shall be able to select the relevant Fruit types.
Step 1: implement MouseListener
public class Bill extends javax.swing.JFrame implements MouseListener
Step 2: set the addMouseListener(this) in to each label. write it inside the constructor.
public class Bill extends javax.swing.JFrame implements MouseListener {
public Bill() {
initComponents();
lblBanana.addMouseListener(this);
lblPoires.addMouseListener(this);
lblApple.addMouseListener(this);
lblPineapple.addMouseListener(this);
lblPomme.addMouseListener(this);
lblMango.addMouseListener(this);
} after implemented the MouseListener it ask to implement all the abstract method of MouseListener.you must implement it.write code inside the mouseClicked event.
public void mouseClicked(MouseEvent e) {
if(e.getSource() == lblBanana){
qty = Double.parseDouble(JOptionPane.showInputDialog("Enter Qty"));
df = (DefaultTableModel)tblTable.getModel();
name = "Banana";
price = 2.40;
System.out.printf("%.2f%n", tot = qty * price);
df.addRow(new Object []{
name,
price,
qty,
tot
});
Double sum = 0.0;
for(int i=0; i < tblTable.getRowCount(); i++)
{
sum = sum + Double.parseDouble(tblTable.getValueAt(i, 3).toString());
}
System.out.printf("%.2f%n", sum);
items = tblTable.getRowCount();
System.out.println(sum);
System.out.println(items);
txtTot.setText(Double.toString(sum));
lblItems.setText(Integer.toString(items));
}
else if (e.getSource() == lblPoires)
{
qty = Double.parseDouble(JOptionPane.showInputDialog("Enter Qty"));
df = (DefaultTableModel)tblTable.getModel();
name = "Poires";
price = 3.0;
tot = qty * price;
df.addRow(new Object []{
name,
price,
qty,
tot
});
Double sum = 0.0;
for(int i=0; i < tblTable.getRowCount(); i++)
{
sum = sum + Double.parseDouble(tblTable.getValueAt(i, 3).toString());
}
System.out.println((int) Math.round(sum));
items = tblTable.getRowCount();
System.out.println(sum);
System.out.println(items);
txtTot.setText(Double.toString(sum));
lblItems.setText(Integer.toString(items));
}
else if (e.getSource() == lblApple)
{
qty = Double.parseDouble(JOptionPane.showInputDialog("Enter Qty"));
df = (DefaultTableModel)tblTable.getModel();
name = "Apple";
price = 1.0;
tot = qty * price;
df.addRow(new Object []{
name,
price,
qty,
tot
});
Double sum = 0.0;
for(int i=0; i < tblTable.getRowCount(); i++)
{
sum = sum + Double.parseDouble(tblTable.getValueAt(i, 3).toString());
}
System.out.println((int) Math.round(sum));
items = tblTable.getRowCount();
System.out.println(sum);
System.out.println(items);
txtTot.setText(Double.toString(sum));
lblItems.setText(Integer.toString(items));
}
else if (e.getSource() == lblPineapple)
{
qty = Double.parseDouble(JOptionPane.showInputDialog("Enter Qty"));
df = (DefaultTableModel)tblTable.getModel();
name = "PineApple";
price = 3.0;
tot = qty * price;
df.addRow(new Object []{
name,
price,
qty,
tot
});
Double sum = 0.0;
for(int i=0; i < tblTable.getRowCount(); i++)
{
sum = sum + Double.parseDouble(tblTable.getValueAt(i, 3).toString());
}
System.out.println((int) Math.round(sum));
items = tblTable.getRowCount();
System.out.println(sum);
System.out.println(items);
txtTot.setText(Double.toString(sum));
lblItems.setText(Integer.toString(items));
}
else if (e.getSource() == lblApple)
{
qty = Double.parseDouble(JOptionPane.showInputDialog("Enter Qty"));
df = (DefaultTableModel)tblTable.getModel();
name = "Apple";
price = 1.0;
tot = qty * price;
df.addRow(new Object []{
name,
price,
qty,
tot
});
Double sum = 0.0;
for(int i=0; i < tblTable.getRowCount(); i++)
{
sum = sum + Double.parseDouble(tblTable.getValueAt(i, 3).toString());
}
System.out.println((int) Math.round(sum));
items = tblTable.getRowCount();
System.out.println(sum);
System.out.println(items);
txtTot.setText(Double.toString(sum));
lblItems.setText(Integer.toString(items));
}
else if (e.getSource() == lblPomme)
{
qty = Double.parseDouble(JOptionPane.showInputDialog("Enter Qty"));
df = (DefaultTableModel)tblTable.getModel();
name = "Pogrante";
price = 1.0;
tot = qty * price;
df.addRow(new Object []{
name,
price,
qty,
tot
});
Double sum = 0.0;
for(int i=0; i < tblTable.getRowCount(); i++)
{
sum = sum + Double.parseDouble(tblTable.getValueAt(i, 3).toString());
}
System.out.println((int) Math.round(sum));
items = tblTable.getRowCount();
System.out.println(sum);
System.out.println(items);
txtTot.setText(Double.toString(sum));
lblItems.setText(Integer.toString(items));
}
else{
qty = Double.parseDouble(JOptionPane.showInputDialog("Enter Qty"));
df = (DefaultTableModel)tblTable.getModel();
name = "Mango";
price = 1.0;
tot = qty * price;
df.addRow(new Object []{
name,
price,
qty,
tot
});
Double sum = 0.0;
for(int i=0; i < tblTable.getRowCount(); i++)
{
sum = sum + Double.parseDouble(tblTable.getValueAt(i, 3).toString());
}
System.out.println((int) Math.round(sum));
items = tblTable.getRowCount();
System.out.println(sum);
System.out.println(items);
txtTot.setText(Double.toString(sum));
lblItems.setText(Integer.toString(items));
}
} public void cal()
{
double tottal = Double.parseDouble(txtTot.getText());
double pay = Double.parseDouble(txtPaid.getText());
double bal;
if(tottal < pay)
{
bal = pay - tottal;
txtBalance.setText(Double.toString(bal));
}
else
{
JOptionPane.showMessageDialog(null, "Not Valied Money ");
}
} public void bill()
{
System.out.println("Bill button clicked");
System.setProperty("file.encoding", "UTF-8");
String total = txtTot.getText();
String pay = txtPaid.getText();
String bal = txtBalance.getText();
DefaultTableModel model = (DefaultTableModel) tblTable.getModel();
// Set the font size
txtbill.setFont(new Font("Arial Black", Font.PLAIN, 10));
txtbill.setText(txtbill.getText() + " ___________________________________________________\n");
txtbill.setText(txtbill.getText() + " DeviJames \n");
txtbill.setText(txtbill.getText() + " Welcome to our shop \n");
txtbill.setText(txtbill.getText() + " ___________________________________________________\n");
// Heading
txtbill.setText(txtbill.getText() + " Product\tPrice\tQty\tAmount\n");
for (int i = 0; i < model.getRowCount(); i++) {
String pname = (String) model.getValueAt(i, 0);
String price = model.getValueAt(i, 1).toString();
String qty = model.getValueAt(i, 2).toString();
String amount = model.getValueAt(i, 3).toString();
txtbill.setText(txtbill.getText() + " " + pname + "\t" + price + "\t" + qty + "\t" + amount + "\n");
}
txtbill.setText(txtbill.getText() + "\n");
txtbill.setText(txtbill.getText() + "\t" + "\t" + " Subtotal : " + total + "\n");
txtbill.setText(txtbill.getText() + "\t" + "\t" + " Pay : " + pay + "\n");
txtbill.setText(txtbill.getText() + "\t" + "\t" + " _______________ "+ "\n");
txtbill.setText(txtbill.getText() + "\t" + "\t" + " Balance : " + bal + "\n");
txtbill.setText(txtbill.getText() + "\n");
txtbill.setText(txtbill.getText() + " ___________________________________________________\n");
txtbill.setText(txtbill.getText() + " THANK YOU COME AGAIN \n");
} private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String tot = txtTot.getText();
if(tot.isEmpty())
{
JOptionPane.showMessageDialog(null, "Total is Empty ");
}
else{
cal();
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// Print Bill
String pay = txtPaid.getText();
String bal = txtBalance.getText();
if(pay.isEmpty() && bal.isEmpty())
{
JOptionPane.showMessageDialog(this, "Paid and Balance is empty ");
txtPaid.requestFocus();
}
else{
try {
bill();
txtbill.print();
} catch (PrinterException ex) {
}
}
} private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
df.setRowCount(0);
txtTot.setText("");
txtPaid.setText("");
txtBalance.setText("");
txtbill.setText("");
lblItems.setText("");
}
If you're just beginning to learn Java GUI programming creating an Water System Calculator is a fantastic project for…
GitHub is a powerful tool used by teams and developers around the globe. This guide is…
It's like having a super-smart buddy that is always there to help you write stories,…
The UK is known for its rich history, diverse culture, and most of all its…
Do you have a plan for your next holiday? Being aware of the Bank Holidays within the…
The world is rapidly changing of software development AI-assisted tools for coding have become the main focus. As…