Java

Bakery Management System Project using Java

This tutorial will teach you how to make a Bakery Management System Project using Java in Java step by step. This system will helpful you to learn Inventory Management System.

Paste the Code inside the Buttons

DefaultTableModel model;
    
    String name;
    int a,tot;
     
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        int sum = 0;
        name = "Buger 1";
         String test1= JOptionPane.showInputDialog("Enter the Qty ");

        a = Integer.parseInt(test1);
        tot = 1000 * a;
        
         model = (DefaultTableModel)jTable1.getModel();
           
           model.addRow(new Object[]          
           {
               name,
               1000,
               a,
               tot
               
           }        
          ); 
           
       for(int i=0; i<jTable1.getRowCount(); i++)
       {
           sum = sum + Integer.parseInt(jTable1.getValueAt(i, 3).toString());  
       }
       
       txtbill.setText(Integer.toString(sum));   
    }                                        

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    
          int sum = 0;
        name = "Buger 2";
         String test1= JOptionPane.showInputDialog("Enter the Qty ");

        a = Integer.parseInt(test1);
        tot = 1000 * a;
        
         model = (DefaultTableModel)jTable1.getModel();
           
           model.addRow(new Object[]          
           {
               name,
               2000,
               a,
               tot
               
           }        
          ); 
           
       for(int i=0; i<jTable1.getRowCount(); i++)
       {
           sum = sum + Integer.parseInt(jTable1.getValueAt(i, 3).toString());  
       }
       
       txtbill.setText(Integer.toString(sum));   
        
    }                                        

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
          int sum = 0;
        name = "Buger 3";
         String test1= JOptionPane.showInputDialog("Enter the Qty ");

        a = Integer.parseInt(test1);
        tot = 1500 * a;
        
         model = (DefaultTableModel)jTable1.getModel();
           
           model.addRow(new Object[]          
           {
               name,
               2000,
               a,
               tot
               
           }        
          ); 
           
       for(int i=0; i<jTable1.getRowCount(); i++)
       {
           sum = sum + Integer.parseInt(jTable1.getValueAt(i, 3).toString());  
       }
       
       txtbill.setText(Integer.toString(sum));   
        
        
        
        
    }                                        

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
          int sum = 0;
        name = "cake 1";
         String test1= JOptionPane.showInputDialog("Enter the Qty ");

        a = Integer.parseInt(test1);
        tot = 1000 * a;
        
         model = (DefaultTableModel)jTable1.getModel();
           
           model.addRow(new Object[]          
           {
               name,
               500,
               a,
               tot
               
           }        
          ); 
           
       for(int i=0; i<jTable1.getRowCount(); i++)
       {
           sum = sum + Integer.parseInt(jTable1.getValueAt(i, 3).toString());  
       }
       
       txtbill.setText(Integer.toString(sum));   
        
    }                                        

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        
          int sum = 0;
        name = "cake 2";
         String test1= JOptionPane.showInputDialog("Enter the Qty ");

        a = Integer.parseInt(test1);
        tot = 1000 * a;
        
         model = (DefaultTableModel)jTable1.getModel();
           
           model.addRow(new Object[]          
           {
               name,
               2000,
               a,
               tot
               
           }        
          ); 
           
       for(int i=0; i<jTable1.getRowCount(); i++)
       {
           sum = sum + Integer.parseInt(jTable1.getValueAt(i, 3).toString());  
       }
       
       txtbill.setText(Integer.toString(sum));   
        
    }                                        

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                         

          int sum = 0;
        name = "cake 3";
         String test1= JOptionPane.showInputDialog("Enter the Qty ");

        a = Integer.parseInt(test1);
        tot = 3000 * a;
        
         model = (DefaultTableModel)jTable1.getModel();
           
           model.addRow(new Object[]          
           {
               name,
               2000,
               a,
               tot
               
           }        
          ); 
           
       for(int i=0; i<jTable1.getRowCount(); i++)
       {
           sum = sum + Integer.parseInt(jTable1.getValueAt(i, 3).toString());  
       }
       
       txtbill.setText(Integer.toString(sum));      
        
    }

Create Print Function

private void printBill() {
        PrinterJob printerJob = PrinterJob.getPrinterJob();
        printerJob.setPrintable(new Printable() {
            @Override
            public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
                if (pageIndex > 0) {
                    return NO_SUCH_PAGE;
                }

                Graphics2D g2d = (Graphics2D) graphics;
                g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());

                // Set the terminal receipt width and start printing content
                Font font = new Font("Monospaced", Font.PLAIN, 12);
                g2d.setFont(font);

                int y = 20;
                g2d.drawString("            Tutusfunny", 10, y);
                y += 20;
                g2d.drawString("--------------------------------", 10, y);
                y += 20;
                g2d.drawString(String.format("%-15s %5s %5s %10s", "Item", "Price", "Qy", "Total"), 10, y);
                y += 20;
                g2d.drawString("--------------------------------", 10, y);
                y += 20;

                for (int i = 0; i < model.getRowCount(); i++) {
                    String item = model.getValueAt(i, 0).toString();
                    String price = model.getValueAt(i, 1).toString();
                    String quantity = model.getValueAt(i, 2).toString();
                    String total = model.getValueAt(i, 3).toString();
                    g2d.drawString(String.format("%-15s %5s %8s %10s", item, price, quantity, total), 10, y);
                    y += 20;
                }

                g2d.drawString("--------------------------------", 10, y);
                y += 20;
                g2d.drawString("              Thanks Come again", 10, y);
                y += 20;
                g2d.drawString("--------------------------------", 10, y);

                return PAGE_EXISTS;
            }
        });

        boolean doPrint = printerJob.printDialog();
        if (doPrint) {
            try {
                printerJob.print();
            } catch (PrinterException ex) {
                ex.printStackTrace();
            }
        }
    }

Call the Print Function inside the Button

printBill();
admin

Recent Posts

Employee Working Hours Calculation System using C#.net

Initialize the employee number, Hourswork,and Hoursrate to calculate a grosswage use the following condition. if…

1 day ago

Java Payroll System Calculate Employee Overtime

Act as a Java developer to create a program that calculates the gross wage for…

3 days ago

Employee Working Hours Calculation System using Java

Initialize the employee number, Hourswork,and Hoursrate to calculate a grosswage use the following condition. if…

4 days ago

Laravel 11 School Management System

In this tutorial, we will teach you how to create a simple school management system…

1 week ago

How to Make Admin Panel Using React MUI

I have design the Admin Basic templete using React MUI Design Admin Dashboard and Login.Here…

3 weeks ago

Install Laravel Breeze for Authentication Using Laravel 11

In this tutorial ,i am to going teach the Laravel Breeze.Laravel Breeze provides a simple…

3 weeks ago