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

ChatGPT Free Online Download the ChatGPT App Easily

Have you ever wanted to talk to a friendly, smart robot that helps you with…

6 days ago

Free GPT Chat? DeepSeek AI Does It Better

DeepSeek AI is becoming a friendly and powerful new tool in the world of artificial…

2 weeks ago

Spring Boot MySQL Complete CRUD REST API [ Free Sourecode ]

Do you want to become an expert in Spring Boot CRUD operations? This comprehensive tutorial…

3 weeks ago

CREATE Responsive Navigation Bar with FlexBox CSS!

Modern websites must have a navigation bar that is clear and responsive. FlexBox CSS is…

4 weeks ago

Registration with image upload Java Jdbc(Download Source code)

Introduction In this section, we will guide you step by step in the development of an image upload registration system in Java using MySQL and JDBC. In the application, users register…

2 months ago

Touchable shop Pos system using Java

The Touchable Shop POS (Point of Sale) system is a sophisticated software solution developed using…

3 months ago